无法以JSON格式显示mysql数据,然后使用相同的谷歌图表进行显示

时间:2013-11-09 06:18:50

标签: php mysql json

下面的代码不显示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;


?>

0 个答案:

没有答案