我一直在尝试创建两个数组,每月数量为0和1。
到目前为止,我已经设法计算返回0和1的条目,但我需要的是0值,其中没有月中的项目。 这是我的代码:
$data1y=array();
$data2y=array();
$months = array();
$sql = "SELECT MONTH( date_in ) AS date_in_month , COUNT( date_in ) AS date_in_count , returned, COUNT( returned ) AS returned_count
FROM item
WHERE date_in >= NOW() - INTERVAL 1 YEAR
GROUP BY MONTH(date_in), returned";
$result = mysql_query($sql);
while(($row = mysql_fetch_assoc($result))) {
if($row['returned']=='0')
{
$data1y[] = $row['returned_count'];
}
if($row['returned']=='1')
{
$data2y[] = $row['returned_count'];
}
}
for ($i = 1; $i <= 12; $i++) {
$months[] = date("M y", strtotime( date( 'Y-m-01' )." -$i months"));
}
我需要的是这样的事情:
$data1y=array(0,80,0,0,47,80,40,116,47,80,40,116);
$data2y=array(0,30,0,0,61,30,82,105,61,30,82,105);