我正在使用谷歌图表API来绘制一些数据。我从MySQL数据库中获取数据并使用MySQL打印它。
<?php
$income_from_clients = $mysql_obj->select ( "
SELECT
sum(invoice.invoice_amount_payable) AS invoice_totals,
company.company_label AS company_label,
MONTHNAME(invoice.invoice_date_paid) AS month,
YEAR(invoice.invoice_date_paid) AS year
FROM invoice INNER JOIN company ON invoice.company_id = company.company_id
WHERE
invoice.invoice_active=1
AND invoice.invoice_status_id=7
AND invoice.invoice_date_deleted=0
AND invoice.invoice_date_paid>='" . $_POST ["start_date_"] . "-" . $_POST ["start_date_month"] . "-" . $_POST ["start_date_date"] . "'
AND invoice.invoice_date_paid<='" . $_POST ["end_date_"] . "-" . $_POST ["end_date_month"] . "-" . $_POST ["end_date_date"] . "'
AND company.company_id=" . $_POST ["company_id"] . "
GROUP BY company.company_id, MONTH(invoice.invoice_date_paid), YEAR(invoice.invoice_date_paid)
ORDER BY YEAR(invoice.invoice_date_paid), MONTH(invoice.invoice_date_paid)" );
echo "data.addRows($mysql_obj->mysql_num_rows);";
$i = 0;
foreach ( $income_from_clients as $ifc ) {
echo "data.setValue($i, 0, '" . $ifc ["month"] . " " . $ifc ["year"] . "');\n";
echo "data.setValue($i, 1, " . $ifc ["invoice_totals"] . ");\n";
$i ++;
}
?>
这样可以正常工作,但是没有发票的任何月份都会被简单地跳过图表,因为它不会从MySQL返回。这几个月我怎么能得到0?
感谢。
答案 0 :(得分:2)
要在MySQL中填充数据中的漏洞,您需要将其与参考表(在您的情况下为日历)连接。
答案 1 :(得分:0)
目前,您正在迭代数据库中的结果,并根据它返回的行输出值。由于它不返回值为0的行,因此您不会在输出中看到这些行。
两种可行的解决方案包括: