我想问一些支持如何实现从PHP中的5个不同MYSQL脚本创建表的想法。它们各自的结果是按月计算的数据组的SUM。 我不希望脚本花费大量时间,因为单独激活时它们都可以。
我会提出理论查询,以免我的信息很长。
<?php
$qry = "SUM(CASH) group by MONTH DESC";
$result=mysql_query($qry) or die(mysql_error());
$qry2 = "SUM(DEBT) group by MONTH DESC";
$result=mysql_query($qry2) or die(mysql_error());
$qry3 = "SUM(DEBTPAID) group by MONTH DESC";
$result=mysql_query($qry3) or die(mysql_error());
$qry4 = "SUM(INVOICE) group by MONTH DESC";
$result=mysql_query($qry4) or die(mysql_error());
$qry5 = "SUM(NVOICEPAYOFF) group by MONTH DESC";
$result=mysql_query($qry5) or die(mysql_error());
?>
我想要实现这样的表:
<table>
<tr>
<td>CASH</td>
<td>DEBT</td>
<td>DEBTPAID</td>
<td>INVOICE</td>
<td>INVOICEPAYOFF</td>
</tr>
<?
echo '<tr>';
echo '<td><label>'. $row['CASH'] .'</label></td>';
echo '<td><label>'. $row2['DEBT'] .'</label></td>';
echo '<td><label>'. $row3['DEBTPAID'] .'</label></td>';
echo '<td><label>'. $row4['INVOICE'] .'</label></td>';
echo '<td><label>'. $row5['INVOICEPAYOFF'] .'</label></td>';
echo '</tr>';
?>
</table>
我将感谢您的每一个想法,解决方案或建议。先感谢您!
答案 0 :(得分:0)
为什么不这样做?
SELECT sum(cash) as 'cash', sum(debt) as 'debt',
sum(debtpaid) as 'debtpaid', sum(invoice) as 'invoice',
sum(invoicepaid) as 'invoicepaid'
FROM my_table
GROUP BY MONTH DESC