Hi guys, I am trying to access a jQuery JSON object, and I can't see anything wrong witj my code, but all I get when I try to access the object is undefined
, I was thinking that maybe it's because of the way it is nested, but I am unsure, here is my code,
function systems(dom_id, id){
$.getJSON("get_systems.php", {uid:id}, function(data){
// here I get the general system info related to the user
$.each(data, function(i, json){
//here I get each systems name, related to each system
$.getJSON('get_system_name.php', {uid:json.product_id}, function(data){
console.log(data.products);
$(dom_id).append('<tr><th>'+data.products+'</th></tr>');
});
});
});
};
The column name with the name of the system in it, is named products
, hence me trying to get the name using data.products
, but all I get is undefined
as I mentioned above.
But when I just log data
it shows the object, which looks like this, [Object { products="this is the product name"}]
and this is the PHP that I use to get the system names,
get_system_name.php:
<?php
$uid = $_GET['uid'];
mysql_connect("localhost", "user", "1234") or die(mysql_error());
mysql_select_db("the_DB") or die(mysql_error());
$query = mysql_query("SELECT products FROM products WHERE product_id='$uid'") or die(mysql_error());
while($array = mysql_fetch_array($query, true)) {
$string[] = $array;
}
$json = json_encode($string);
echo $json;
?>
Thanx in advance!