我有这段代码,输出是:{"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();
?>
但我需要这样的事:{1750}。
任何帮助?
答案 0 :(得分:4)
试试这个:
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();
记住json需要一个something: something_else
所以你可能会在这里得到一个错误,因为现在没有编码的数组