我在PHP中有这个代码:
$sql = '
SELECT t1.name, t2.code, COUNT(t2.code) as cnt
FROM t1
LEFT JOIN t2
ON t2.code = t1.code2
WHERE (t2.input_date BETWEEN "2015-04-01" AND "2015-04-29")
AND t2.serial = 5
GROUP BY t2.code HAVING (t2.code>0)';
$Chartdata= mysql_query($sql) or die(mysql_error());
$arr = array();
while ($row = mysql_fetch_assoc($Chartdata)) {
$arr[] = $row;
}
echo json_encode($arr);
此代码在我的浏览器上显示空白页面。我试图删除最后一个“AND”和“GROUP BY ...”,它显示1个值。
答案 0 :(得分:0)
尝试:
$sql = '
SELECT t1.name, t2.code, COUNT(*) as cnt
FROM t1
LEFT JOIN t2
ON t2.code = t1.code2
WHERE (t2.input_date BETWEEN "2015-04-01" AND "2015-04-29")
AND t2.serial = 5
AND t2.code>0
GROUP BY t2.code';