user2353155
user2353155

Reputation: 13

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

I'm trying to pass a value by href to PHP to return the rest of the data in that row of my mysql database table.

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                      

that ID number. I'm pretty sure both the href and the php are flawed.

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'];

?>

Any help is appreciated.

Upvotes: 0

Views: 1491

Answers (2)

Noman
Noman

Reputation: 4116

try this , you forget to use "data": right after

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

copy below code .

<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>

Upvotes: 0

Youness
Youness

Reputation: 1495

change :

$id_num = id_num;

to

$id_num = $_GET['id_num']; 

and the link on the previous page should be :

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

PS : value should be replaced by the real ID_NUM

Upvotes: 3

Related Questions