[請益] 正確迴圈方法?

作者: lcy17 (Aoie)   2017-04-18 16:58:33
各位前輩好
我有做個訂單資訊
我目前的code會使總資訊出現在每一筆細項的下方
如果我只想一筆訂單出現一次總資訊
請問我的做法要怎麼改呢?
我目前有想到foreach
可是條件式 as 那邊不知道要怎麼放
圖片是長這樣 應該知道我在說什麼了吧QQ
http://i.imgur.com/agCkAGB.jpg
<?php while ($drow = $drs->fetch_assoc()): ?>
<table class="rwd-table table-bordered table-responsive">
<tr >
 <th>訂單編號</th>
 <th>商品明細</th>
 <th>數量</th>
<th>價格</th>
 </tr>
 <tr>
 <td data-th="訂單編號" class="product-num"><?=
$drow['sid'] ?></td>
 <td data-th="商品明細" class="product"><p><?=
$drow['product_name'] ?></p></td>
 <td data-th="數量" class="product-howmany"><p><?=
$drow['qty'] ?></p></td>
<td data-th="價格" class="product-price"><p><?=
$drow['price'] ?></p></td>
</tr>
</table>
<div class="total">
<p>共&nbsp;<?= $drow['totalqty'] ?>&nbsp;項產品</p><br>
<p>總金額: <?= $drow['total'] ?></p>
<p>配送方式:<?= $drow['delivery'] ?></p>
<p>付款方式:<?= $drow['payment'] ?></p>
<p>寄送地址:<?= $drow['address'] ?></p><br>
</div>
<?php endwhile; ?>
作者: Phedra (Phedra)   2017-04-19 00:09:00
total 那一列通常不會寫在迴圈裡,而是獨立在迴圈結束後才處理。1. 先用迴圈顯示每項產品 (同時間可以先計算總額但不顯示)2. 迴圈結束之後,再接著處理並顯示 total 那一行

Links booklink

Contact Us: admin [ a t ] ucptt.com