我下面的代码给出了 JSON 输出,但金额值非常高。另一方面,当我单独执行 mysql 查询时,金额值是当前的。
php 函数是否创建了错误的值?
<?php
$DB_NAME = 'mro';
$DB_HOST = 'localhost';
$DB_USER = 'mysql';
$DB_PASS = 'sql';
$mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "select a.obook as code,sum(a.amt) as Amount from mtrans a where orgdate between '20131001' and '20131031' and a.obook <> '1' group by a.obook";
if ($result = $mysqli->query($query)) {
{
$rows = array();
$table = array();
$table['cols'] = array(
array('label' => 'Book', 'type' => 'string'),
array('label' => 'Amount', 'type' => 'number')
);
while ($row = $result->fetch_assoc()) {
$temp = array();
$temp[] = array('v' => "Store books");
$temp[] = array('v' => (int) $row['Amount']);
$rows[] = array('c' => $temp);
}
}
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);
echo $jsonTable;
?>