我有一个带有订单的应用程序。所以在数据库中有一个带有TableID的记录 日期,时间,产品ID以及订购该产品的次数。订购产品但在相同的表格,日期和时间上应在同一张收据上。但显示不同(参见照片)。我已经按日期和时间订购了它们。但是当我按TableNr分组时,它不会显示同一tableNr中的多个项目(请参见第二张照片)
<?php
$checkbestelling = "SELECT *, gerecht.Prijs*bestelling.Aantal AS Totaalprijs FROM bestelling
LEFT JOIN menuitem ON bestelling.MenuItemID = menuitem.MenuItemID
LEFT JOIN gerecht ON gerecht.GerechtID = menuitem.GerechtID ORDER BY Datum, Tijd ASC";
foreach ($db->query($checkbestelling) as $bestellingen){
?>
<div class="col-lg-4" style="margin-bottom:25px;">
<div class="card mb-5 mb-lg-0">
<div class="card-body">
<h5 class="card-title text-muted text-uppercase text-center">Tafel <?php echo $bestellingen["Tafel"];?></h5>
<h6 class="card-price text-center"><span class="period">Datum: <?php echo date("d-m-Y", strtotime($bestellingen["Datum"]));?></span></h6>
<h6 class="card-price text-center"><span class="period">Tijd: <?php echo $bestellingen["Tijd"];?></span></h6>
<hr>
<ul class="list-group list-group-flush text-center">
<li class="list-group-item nb">Product: <?php echo $bestellingen["Gerecht"];?></li>
<li class="list-group-item nb">Aantal: <?php echo $bestellingen["Aantal"];?></li>
<li class="list-group-item nb">Prijs: €<?php echo $bestellingen["Totaalprijs"];?></li>
</ul>
<button type="button" class="btn btn-lg btn-block btn-primary bgcb" onclick="printDiv('printable')">Print bon</button>
<button type="button" class="btn btn-lg btn-block btn-primary bgcr">Verwijder</button>
</div>
</div>
</div>
<?php } ?>
答案 0 :(得分:0)
嗯,问题出在查询中,您正在按日期对它们进行排序,但是您也应该按日期对它们进行分组(“ GROUP BY”),因此它将同一日期的所有行进行分组。
示例:
SELECT SUM(foo), DATE(mydate) FROM a_table GROUP BY DATE(a_table.mydate);