Reputation: 635
I have applied query to show order details in a table according to names and dates. It shows data correct.Right now its displaying data like this:
But now i want my data to be shown in format where i can see all the orders from same client according to date something like this:
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
Any suggestions or help will be appreciable
Code
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>
Upvotes: 1
Views: 215
Reputation: 133360
Try adding order by this way
$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";
Upvotes: 1
Reputation: 298
Use Group BY Order_date
. If there are multiple orders from same customer Use SUM(quantity)
and distinct(Itemname)
.
Upvotes: 0