订单详细信息显示ORDER BY日期和名称

时间:2015-12-17 21:37:37

标签: php sql mysqli

我已应用查询以根据名称和日期在表格中显示订单详细信息。它显示数据正确。现在它显示如下数据:

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>

2 个答案:

答案 0 :(得分: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";

答案 1 :(得分:0)

使用Group BY Order_date。如果来自同一客户的多个订单使用SUM(quantity)distinct(Itemname)