2015-12-17 30 views
1

我已應用查詢以根據名稱和日期在表中顯示訂單詳細信息。它顯示的數據correct.Right現在它的顯示數據是這樣的:訂單明細顯示ORDER BY日期和名稱

enter image description here

但現在我想在格式,我可以按日期這樣的事情看到來自同一個客戶的訂單,以顯示我的數據:

ABC ordered on Date:20/05/15 

ItemName | Size | Quantity | Color 
item1 | XL |  7 | yellow 
item2 | L |  3 | pink 
item3 | S |  1 | green 

XYZ ordered on Date:13/09/15 

ItemName | Size | Quantity | Color 
item1 | L |  8 | brown 
item2 | L |  3 | pink 
item3 | S |  4 | green 

任何建議或幫助將很可觀

代碼

echo" <table border='3px' bordercolor='#333333' >"; 
$query="select orders.date,order_detail.quantity,order_detail.price,order_detail.color,order_detail.size,customers.name,products.product_name,products.product_image from order_detail JOIN orders on orders.serial=order_detail.orderid Join customers on customers.serial=orders.customerid Join products on products.productid=order_detail.productid "; 
$sql=mysqli_query($con,$query); 
while($row=mysqli_fetch_array($sql)) 
{ 
    ?> 
    <tr> 
    <td><?php echo $row['name'] ?> </td> 
    <td><?php echo $row['date'] ?></td> 
    </tr> 
    <th>Product</th> 
     <th>Name & quantity</th> 
     <th>Color</th> 
     <th>Price</th> 
     <th>Size</th> 
     <tr> 
    <td><image width="80px" height="90px" src="\images<?php echo $row['product_image'] ?>"/></td> 
    <td><?php echo $row['product_name']. "*". $row['quantity']?></td> 
    <td><?php echo $row['color'] ?></td> 
    <td><?php echo $row['price'] ?></td> 
    <td><?php echo $row['size'] ?></td> 
    </tr> 
    <?php 
     } } 
    ?> 
    </table> 

回答

0

使用Group BY Order_date。如果同一客戶有多個訂單,請使用SUM(quantity)distinct(Itemname)

+0

添加順序,如果你能提供一個合適的查詢它會幫助我瞭解更多 – tabia

1

試圖通過這種方式

$query="select orders.date,order_detail.quantity, 
    order_detail.price,order_detail.color, 
    order_detail.size,customers.name,products.product_name, 
    products.product_image from order_detail 
    JOIN orders on orders.serial=order_detail.orderid 
    Join customers on customers.serial=orders.customerid 
    Join products on products.productid=order_detail.productid 
    order by orders.date ASC, product.name ASC"; 
+0

它仍然會顯示日期和名稱,每行。 – tabia

+0

你是什麼意思...查詢的結果只是按照順序定義的方式排序..你顯示的日期和名稱在一行或兩行中與你的html相關 – scaisEdge

+0

否則如果你想要一個文檔的主詳細結構,你應該做的訂單的主查詢和foreach的物品的detil查詢.. – scaisEdge

相關問題