我試圖顯示來自查詢的結果,但無法顯示它應該顯示的結果。 我有兩個表 - ordersheader
和orderitems
。顯示來自查詢的數據 - 我無法正確顯示
ordersheader
是訂單表。它的結構是: idOrder
,idCustomer
,createdDate
,orderDueDate
。
我的表 '的OrderItems' 包含。它具有下列結構中的每個單獨的順序的OrderItems: orderitem_id
,idOrder
,item_number
,eggSize
,quantity
,price
。
這兩個表加入了ON IDOrder。 ordersheader
中的一行對應於orderitems
中的許多行,因爲一個訂單可能包含許多訂貨項。 我的問題是我無法正確顯示它們。它要顯示這樣的:
,當您單擊詳細信息應該看起來像:
現在,他們都顯示在這樣的新行一個OrderItem的:
http://prntscr.com/7lworg 我必須使每個idOrder的結果顯示在一行中。 我應該使用內部循環,以及如何做到這一點? 我的模式是:
<?php
function getOrders(){
$date = new DateTime("now");
$curr_date = $date->format('Y-m-d');
$this->db->select('ordersheader.*,customer.name,orderitems.*');
$this->db->from('ordersheader');
$this->db->join('orderitems', 'orderitems.idOrder = ordersheader.idOrder');
$this->db->join('customer', 'customer.idCustomer = ordersheader.idCustomer');
$this->db->where('DATE(orderDueDate)', $curr_date);
$query = $this->db->get();
return $query->result();
我的看法是:
<?php
if($orderlist){
foreach($orderlist as $row) {
?> <tr class="overview">
<td><?php echo $row->idOrder; ?></td>
<td class="text-center"><img src="<?= base_url();?>/assets/images/tick.png"></td>
<td><?php echo $row->name; ?></td>
<td><?php echo $row->eggSize; ?></td>
<td><?php echo $row->quantity; ?></td>
<td>
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: 60%;">
60%
</div>
</div>
</td>
<td>18:00</td>
<td><button type="button" class="btn btn-link btn-xs view-full-order">Full</button></td>
</tr> <?php for($i=0;$i<count($row->eggSize); $i++) { ?>
<tr class="full hide">
<td></td>
<td></td>
<td></td>
<td><?php echo $row->eggSize; ?></td>
<td><?php echo $row->quantity; ?></td>
<td>
<div class="progress">
<div class="progress-bar progress-bar-info" role="progressbar" style="width: <?php echo $rand; ?>%;">
<?php echo $rand; ?>%
</div>
</div>
</td>
<td>14:00</td>
<td></td>
</tr><?php } ?>
<?php } } ?>
</tbody></table>
試試你的qyery用'$這個 - > DB->其中('DATE(ordersheader.orderDueDate)',$ curr_date);' – Saty
我做到了這一點:$ this-> db-> where('DATE(orderDueDate)',$ curr_date);此列orderDueDate僅在表'ordersheader'中。問題是每個訂單都有很多訂單項,我想將它們合併爲一個訂單。 –
在您的查詢中使用group by – Saty