<?php
$query4 = "SELECT bill.agent_id, bill.date, bill.amount, bill.cheque, bill_agents.id,bill_agents.name ".
"FROM bill, bill_agents ".
"WHERE bill.agent_id = bill_agents.id AND YEAR(date) = YEAR(CURDATE()) AND MONTH(date) = MONTH(CURDATE()) ".
"ORDER BY bill.date ASC";
$result4 = mysql_query($query4) or die('Error, query failed1');
if ( mysql_num_rows( $result4 ) > 0 ) {
mysql_data_seek( $result4, 0 );
?>
<?php while( $row4 = mysql_fetch_array( $result4, MYSQL_ASSOC ) ) { ?>
<tr>
<td><?php echo $row4['name']; ?></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<?php } } ?>
</table>
到这里为止,这段代码对我来说很好用
billTable 结构
bill_agents 表结构
当前结果显示 http://i.stack.imgur.com/tMH3P.jpg
我要显示的结果是我想要每日收款报告第 1 天到第 31 天(也应该按金额和支票的总和)它是如何可能的
结果应该是这样 http://i.stack.imgur.com/S08or.jpg
"GROUP BY bill.agent_id".
此外,在使用上面使用的相同 SQL 并粘贴在下面时,我也遇到了错误。
$query4 = "SELECT bill.agent_id, bill.date, bill.amount, bill.cheque, bill_agents.id,bill_agents.name ".
"FROM bill, bill_agents ".
"WHERE bill.agent_id = bill_agents.id AND YEAR(date) = YEAR(CURDATE()) AND MONTH(date) = MONTH(CURDATE()) ".
"GROUP BY bill.agent_id".
"ORDER BY bill.date ASC";