我试图通过href将值传递给php页面以从mysql数据库的该行检索其余数据

时间:2014-08-07 13:34:35

标签: php html mysql sql href

我正在尝试通过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                      

该ID号。我很确定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'];

?>

感谢任何帮助。

2 个答案:

答案 0 :(得分:3)

改变:

$id_num = id_num;

$id_num = $_GET['id_num']; 

,上一页的链接应为:

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

PS: value应替换为真实ID_NUM

答案 1 :(得分:0)

试试这个,你忘了在

之后立即使用&#34;数据&#34;:
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>