【问题标题】:I'm trying to pass a value by href to a php page to retrieve the rest of the data from that row of a mysql database我正在尝试通过 href 将值传递给 php 页面,以从 mysql 数据库的该行中检索其余数据
【发布时间】:2014-09-30 18:45:06
【问题描述】:

我正在尝试通过 href 向 PHP 传递一个值,以返回我的 mysql 数据库表的该行中的其余数据。

so  when I click on  <a href="datainflux.php?id=id_num>Details</a>

 I want it to send the id number (id=id_num) to datainflux.php to return the 'item', 'ranking', 'descript' and 'type' that use                      

那个身份证号码。我很确定 href 和 php 都有缺陷。

This is the PHP code I'm using

<?php
$hostname="localhost"; //local server name default localhost
$username="root";  //mysql username default is root.
$password="";       //blank if no password is set for mysql.
$database="spkwi312_Organic";  //database name which you created
$con=mysql_connect($hostname,$username,$password);
  if(! $con)
    {
      die('Connection Failed'.mysql_error());
}

mysql_select_db($database,$con);


$id_num = id_num

$query = sprintf("SELECT item, ranking, descript, type FROM og4real 
   WHERE id_num='%s'",
   mysql_real_escape_string($id_num));

$result = mysql_query($query);

if (!$result) {
   $message  = 'Invalid query: ' . mysql_error() . "\n";
   $message .= 'Whole query: ' . $query;
   die($message);
  }

while ($row = mysql_fetch_assoc($result)) {
  echo $row['item'];
  echo $row['ranking'];
  echo $row['descript'];
  echo $row['type'];

?>

感谢任何帮助。

【问题讨论】:

  • 将 $id_num = id_num 更改为 $id_num = $_GET['id_num'];并像 2 一样通过
  • 您的工作代码中缺少一个分号 $id_num = id_num - IF大 IF),它会破坏它.使用适当的错误报告方法,就会表明这一点。
  • 您的问题是什么?你有什么错误?看这里stackoverflow.com/help/how-to-ask

标签: php html mysql sql href


【解决方案1】:

改变:

$id_num = id_num;

$id_num = $_GET['id_num']; 

上一页的链接应该是:

<a href="datainflux.php?id_num=value">Details</a>

PS : value 应该换成真正的ID_NUM

【讨论】:

  • 更改$id_num = id_num;?到....好的(将+1),但谁说$id_num = id_num 不是OP 实际代码的一部分?让我们看看 OP 是否会接听my comment。也许它在那里,但从表面上看,OP 的代码会在那一行中断。
【解决方案2】:

试试这个,你忘了用“数据”:

dataSource: {
            "chart": {
            "caption": "Monthly revenue for last year",
            "subCaption": "Harry's SuperMart",
            "xAxisName": "Month",
            "yAxisName": "Revenues (In USD)",
            "theme": "zune"
            },

复制下面的代码。

<html>
    <head>

        <title>My first chart using FusionCharts Suite XT</title>
        <script type="text/javascript" src="fusioncharts/fusioncharts.js"></script>
        <script type="text/javascript" src="fusioncharts/themes/fusioncharts.theme.zune.js"></script>
        <script type="text/javascript">
        FusionCharts.ready(function(){
    var revenueChart = new FusionCharts({
        type: "column2d",
        renderAt: "chartContainer",
        width: "500",
        height: "300",
        dataFormat: "json",
        dataSource: {
            "chart": {
            "caption": "Monthly revenue for last year",
            "subCaption": "Harry's SuperMart",
            "xAxisName": "Month",
            "yAxisName": "Revenues (In USD)",
            "theme": "zune"
            },
            "data": <?php
    $objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
    $objDB = mysql_select_db("customer");
    $strSQL = "SELECT CustomerID, Budget FROM customer";
    $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");

    $json = array();

    while($r=mysql_fetch_array($objQuery)){

    $json[] = $r;

    }

    //Display the JSON data
    echo $json_data=json_encode($json); 

    mysql_close($objConnect);

    ?>
        }
        }
    });
    revenueChart.render("chartContainer");
});  


        </script>
        </head>
        <body>
        <div id="chartContainer">FusionCharts XT will load here!</div>
        </body>
        </html>

【讨论】:

    猜你喜欢
    • 2019-02-15
    • 2022-01-20
    • 1970-01-01
    • 2015-01-03
    • 1970-01-01
    • 1970-01-01
    • 2018-08-26
    • 1970-01-01
    • 2016-11-03
    相关资源
    最近更新 更多