problem with query -php/json
i have this code, and the output is: {"round (avg (salary), 0)":"1750"}
function tableOne() {
$query = mysql_query("select round (avg (salary), 0) from worker, formation_area where id_formation_area=1") or 开发者_如何学Godie(mysql_error());
$row = mysql_fetch_assoc($query);
$result = $row;
echo json_encode($result);
}
tableOne();
?>
but i need something like this: {1750}.
Any help?
Try this:
function tableOne() {
$query = mysql_query("select round(avg (salary), 0) as `round_avg` from worker, formation_area where id_formation_area=1") or die(mysql_error());
$row = mysql_fetch_assoc($query);
$result = $row['round_avg'];
echo json_encode($result);
}
tableOne();
Remember json needs a something: something_else
so you might get an error here since now there is no array being encoded
精彩评论