Reputation: 4047
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 die(mysql_error());
$row = mysql_fetch_assoc($query);
$result = $row;
echo json_encode($result);
}
tableOne();
?>
but i need something like this: {1750}.
Any help?
Upvotes: 0
Views: 111
Reputation: 146302
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
Upvotes: 4