0
我的查詢從數據庫中獲取下面的數據。php代碼顯示總共列數
這是正確的,但我也需要像下面總顯示所有行的總和..
我怎麼能做到這一點...
我需要顯示最後一行totalbooking列的總和。 。
bookno bookingdate totalbooking
401 15-03-2015 1
401 16-03-2015 2
404 15-03-2015 1
Total 4
下面是我的代碼...
<?php
if($_POST && isset($_POST['Submit']))
{
if($_POST['hawkername']=='All')
{
$cityname = $_SESSION['Auth']['city'];
$data = $database->getRows("SELECT RE.book_no AS book, RE.bookingdate AS bookingdate, HM.hawker_name AS hawkername,SAM.tehsil AS centername,
COUNT(DISTINCT RE.receipt_no) AS totalbooking,SUM(DISTINCT RE.receipt_no) AS final FROM receipt_entry RE INNER JOIN hawker_master HM ON HM.id = RE.hawkername INNER JOIN sub_agent_master SAM ON SAM.id = RE.subagentname WHERE RE.city_name = :cityname GROUP BY RE.hawkername, RE.book_no",array(':cityname'=>$cityname));
}
?>
<?php if (is_array($data)) { foreach($data as $row){ ?>
<tr>
<td><?php echo htmlspecialchars($row['book']); ?></td>
<td><?php echo htmlspecialchars($row['bookingdate']); ?></td>
<td><?php echo htmlspecialchars($row['totalbooking']); ?></td>
</tr>
<?php } } ?>
<tr>
<td>Total</td>
<td></td>
</tr>
共創建變量 - '$總= 0'並添加每個totalbooking在環 - '$總額+ = $行[ 'totalbooking'];'。然後回顯總數。 – Sean 2015-04-02 15:45:18
好的謝謝它的工作謝謝.. – 2015-04-02 15:53:19