实际mysql查询输出和JSON输出的区别

时间:2013-11-11 09:03:41

标签: php mysql

我的下面代码给出了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;
?>

0 个答案:

没有答案