duanrongshi1544 2019-05-20 11:42
浏览 103

使用带有不同行的foreach循环显示多个产品

I have an application with Orders. So in the db there is a record with TableID Date, Time, ProductID and how many times that product is ordered. When a product is ordered but its on the same table and date and time it should be on the same receipt. but it displays different(See photos). I already order them by date and time. but when i group it by TableNr it doesnt display multiple items from the same tableNr (see 2nd photo)

Photo 1: enter image description here

Photo 2: enter image description here

db

<?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 } ?>
  • 写回答

1条回答 默认 最新

  • doufuxing8562 2019-05-20 11:56
    关注

    Well, the issue is on your Query, you are Ordering them by Date, but you should be grouping them by date ("GROUP BY") too, so it groups all the rows from the same date.

    Example:

    SELECT SUM(foo), DATE(mydate) FROM a_table GROUP BY DATE(a_table.mydate);
    
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料