我已经进行了查询,其中显示了已登录的电子邮件ID的宝贵购买数据。我成功完成了这个。现在我想根据日期显示数据。这里显示每行的日期。请提出任何建议!!
代码
<h3>My Orders</h3>
<table border="1">
<?php
$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 where customers.email='$email'";
$sql=mysqli_query($con,$query);
while($row=mysqli_fetch_array($sql))
{
?>
<tr>
<td><?php echo $row['date'] ?></td>
<td><image width="80px" height="90px" src="images/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 :(得分:0)
您是否尝试过按日期排序?这可以通过添加&#34; ORDER BY column ASC
&#34;轻松完成。增加价值或&#34; ORDER BY column DESC
&#34;减少价值!
$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
WHERE customers.email='$email'
ORDER BY orders.date";
查看manual
如果要将同一天组合在一起,请尝试使用GROUP BY命令(如果orders.date的类型为DATE / DATETIME / TIMESTAMP,则此示例有效):
$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
WHERE customers.email='$email'
GROUP BY DATE( orders.date )
ORDER BY orders.date";
如果您使用PHP时间戳或INT,则需要将日期转换为:GROUP BY DATE( FROM_UNIXTIME( orders.date ) )
。
DATE(col)将日期/日期时间/时间戳转换为单日。 GROUP BY将具有相同DATE的所有行放入一行。现在您可能希望将显示的数据也更改为SUM(order_detail.price)以获取当天的总价格,依此类推。