Filkatron Filkatron - 1 year ago 79
SQL Question

Dynamic row with JSON and PHP won't output data

I'm having trouble generating dynamic table rows with data in them. The data is being fetched from a db with a PHP script, and the client side is being handled with jQuery.
This code just displays empty table rows without the data values.

Can someone check what exactly is wrong with it?

The js script:

if(odabrano === "g"){

$.getJSON("nutritional_value.php?value=" + encodeURI(value), function (data) {
var ttr = $("<tr />");
$.each(data, function(k, v){
$("<td />").text(v * (parseFloat(uneseno, 10) / 100)).appendTo(ttr);


The PHP script:


include 'connect.php';

//$value = $_SERVER['QUERY_STRING'];
$value = $_GET['value'];

$query = mysql_query("SELECT NAME, FAT, FIBER, SUGARS FROM ccm WHERE NAME LIKE '$value%'");
while( $run = mysql_fetch_array($query)){
/* $name = $run['NAME'];
$fat = $run['FAT'];
$fiber = $run['FIBER'];
$sugars = $run['SUGARS']; */

$results = array();
//Send it to the client in json format:



Answer Source

I think you're not passing a value for the javascript variable value

What happens if you change the getJSON javascript line to this:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download