大家好,我想就我的问题寻求帮助..
我的查询中有4个变量:
$sql1 = mysql_num_rows(mysql_query("SELECT * FROM tbl_reservation WHERE YEAR(date_added) = YEAR(NOW()) AND order_action = 'Online Transaction' "));
$sql2 = mysql_num_rows(mysql_query("SELECT * FROM tbl_reservation WHERE YEAR(date_added) = YEAR(NOW()) AND order_action = 'Walkin Transaction' "));
$sql3 = mysql_num_rows(mysql_query("SELECT * FROM tbl_reservation WHERE YEAR(date_added) = YEAR(NOW())-1 AND order_action = 'Online Transaction' "));
$sql4 = mysql_num_rows(mysql_query("SELECT * FROM tbl_reservation WHERE YEAR(date_added) = YEAR(NOW())-1 AND order_action = 'Walkin Transaction' "));
我想把它们放在一个阵列中......完全符合我的期望。
以下是我的示例代码:
$stack = array($sql1, $sql2);
array_push($stack, $sql3, $sql4);
$query = print_r($stack);
$result = $query;
print json_encode($result);
在我的浏览器上显示如下:
数组([0] => 0 [1] => 8 [2] => 0 [3] => 1)true
但我想这样显示: [{" 0"" 1"}, {" 2"," 3"}]
我打算在这上面制作一个折线图..我有一个Chart.min.js和jquery.min.js
如果有任何方式..重点..我想制作一个线图,可以比较我当前年份到去年的数据。
请帮帮我。 :(
答案 0 :(得分:0)
试一试
<?php
$a = array(0,8,0,1) ;
echo "<pre>";print_r(json_encode(array_chunk($a, 2)));
?>
。你可以得到这个结果
[[0,8],[0,1]]
顺便问一下,为什么你需要用你的阵列呢?
被修改
在我再次检查您的问题后,您需要获取order
<?php
$stack = array(0,8,0,1) ;
$array2= array();
foreach ($stack as $key => $val) {
$array2[] = $key;
}
echo "<pre>";print_r(json_encode(array_chunk($array2, 2)));
?>