我想问一些支持如何实现从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)
如果我理解正确,那么查询就无法组合(尽管可能不是这样,我们需要完整的查询才能看到)。在这种情况下,你可以简单地做:
$row = array();
$qry = "SUM(CASH) group by MONTH DESC";
$result=mysql_query($qry) or die(mysql_error());
$row['cash'] = mysql_fetch_field($result);
$qry2 = "SUM(DEBT) group by MONTH DESC";
$result=mysql_query($qry2) or die(mysql_error());
$row['debt'] = mysql_fetch_field($result);
$qry3 = "SUM(DEBTPAID) group by MONTH DESC";
$result=mysql_query($qry3) or die(mysql_error());
$row['debtpaid'] = mysql_fetch_field($result);
$qry4 = "SUM(INVOICE) group by MONTH DESC";
$result=mysql_query($qry4) or die(mysql_error());
$row['invoice'] = mysql_fetch_field($result);
$qry5 = "SUM(INVOICEPAYOFF) group by MONTH DESC";
$result=mysql_query($qry5) or die(mysql_error());
$row['invoicepayoff'] = mysql_fetch_field($result);
//Add HTML Table here.
foreach($row as $val){
echo '<td><label>'. $row['CASH'] .'</label></td>';
}
您应该考虑更换mysql_函数。这些现已弃用。