0

下面的代码不以 JSON 格式显示数据,不确定我哪里出错了,使用下面的代码我必须显示生成谷歌图表的数据,请帮忙。

<?php


include ("db/Config.php"); 

$query = mysql_query('select b.ifbank as Bank,sum(a.amt) as Amount from mtrans a JOIN ifsc b on b.ifscd=a.ifsc and orgdate between "20121001" and "20121031" group by bank');

$table = array();
$table['cols'] = array(

    array('label' => 'Bank', 'type' => 'string'),
    array('label' => 'Amount', 'type' => 'number')
);

$rows = array();
while($r = mysql_fetch_assoc($query)) {
    $temp = array();
    $temp[] = array('v' => $r['Bank']);
    $temp[] = array('v' => (int) $r['Amount']); // typecast all numbers to the appropriate type (int or float) as needed - otherwise they are input as strings

    $rows[] = array('c' => $temp);
}


$table['rows'] = $rows;

$jsonTable = json_encode($table);


header('Cache-Control: no-cache, must-revalidate');

header('Content-type: application/json');

echo $jsonTable;


?>
4

0 回答 0