我想对我的问题有一些帮助,我显示在一段时间内获得的总销售额,我已成功完成,现在我需要的是如何显示导致总数的所有单个价格。例如,总数是10,我买4个苹果,6个是橙子,10是总价。
我在这里使用输入类型日期
在一个时间段内显示它$datefrom = $_GET['datefrom'];
$dateto = $_GET['dateto'];
$qry = "SELECT sum(order_detail.quantity*order_detail.price) as chenes, orders.date
FROM order_detail
LEFT JOIN orders ON order_detail.orderid=orders.serial
WHERE date(orders.date) BETWEEN '$datefrom' AND '$dateto'";
mysql_set_charset("UTF8");
$result = @mysql_query($qry);
while ($row=mysql_fetch_array($result)){
echo "Sales from ".date("F d Y",strtotime($datefrom))." ";
echo "to ".date("F d Y",strtotime($dateto))." are a total of ";
echo "₱".number_format($row['chenes'],2);
}
这是我的代码,用于显示每个orderid的单独价格。
$AAA = "SELECT order_detail.quantity,order_detail.price,order_detail.orderid, orders.date
FROM order_detail
LEFT JOIN orders ON order_detail.orderid=orders.serial
WHERE orderid=3";
$BBB=@mysql_query($AAA);
while($CCC=mysql_fetch_array($BBB)){
echo "<br>".$CCC['price']."<br>";
}
它有效,但到目前为止我还不知道如何在没有orderid的情况下自动显示它。
请帮我显示每个的价格,因为到目前为止我只显示了总数,而我现在需要的是显示总数而且它是分解的。我已经尝试过上面的查询,到目前为止我被卡住了。请帮忙 。谢谢。
答案 0 :(得分:2)
通过使用此查询,您将在foreach orderid的不同两列中获得逗号分隔的数量和价格。
SELECT GROUP_CONCAT(IFNULL(od.quantity,0)) AS quantity,
GROUP_CONCAT(IFNULL(od.price,0)) AS price,
od.orderid,o.date
FROM orders o
LEFT JOIN order_detail od ON od.orderid=o.serial
GROUP BY o.serial;
答案 1 :(得分:0)
我修复了你的代码。
$qry = "SELECT sum(order_detail.quantity*order_detail.price) as chenes, orders.date, order_detail.price
FROM order_detail
LEFT JOIN orders
ON order_detail.orderid=orders.serial
WHERE date(orders.date) BETWEEN '$datefrom' AND '$dateto'";
$result = @mysql_query($qry);
while ($row=mysql_fetch_array($result)){
echo "Sales from ".date("F d Y",strtotime($datefrom))." ";
echo "to ".date("F d Y",strtotime($dateto))." are a total of ";
echo "₱".number_format($row['chenes'],2);
$AAA = "SELECT order_detail.quantity*order_detail.price as xax,order_detail.price,order_detail.orderid, orders.date
FROM order_detail
LEFT JOIN orders
ON order_detail.orderid=orders.serial
WHERE date(orders.date) BETWEEN '$datefrom' AND '$dateto'";
$BBB=@mysql_query($AAA);
while($CCC=mysql_fetch_array($BBB)){
echo "<br>".$CCC['xax']."<br>";
}
}
根据我读过的评论,这就是我所做的。根据您的帖子创建了一个新查询,并添加了您的WHERE子句。