将具有共同数据的表行分组为一行

时间:2019-02-18 01:53:52

标签: php html

我有一个HTML表格,其中显示了系统中注册的销售额。问题是,如果客户购买了例如40件商品,该表将显示40行,其中包含每件商品的详细信息。

我需要的是将客户购买的所有商品分组在同一行,第一行是购买的第一个产品,如果您购买了多个产品,请单击一个按钮,将其展开并显示其他行

我将HTML代码保留在表格的格式中

HTML:

<div class="content-wrapper">

   <section class="content-header">

    <h1>
      Sales
    </h1>

    <ol class="breadcrumb">

      <li><a href="home"><i class="fa fa-dashboard"></i> Home</a></li>

      <li class="active">Sales</li>

    </ol>

  </section>


  <section class="content">

    <div class="box"> 

      <div class="box-header with-border">

        <?php

        include "home/sales-graphic.php";

        ?>

      </div>

      <div class="box-body">

        <div class="box-tools">

          <a href="views/modules/report.php?report=sales">

              <button class="btn btn-success">Download report</button>

          </a>

        </div>

        <br>

        <table class="table table-bordered table-striped dt-responsive salesTable" width="100%">

          <thead>

            <tr>

              <th style="width:10px">#</th>
              <th>Product</th>
              <th>Client</th>
              <th>Price</th>       
              <th>Email</th>
              <th>Address</th>
              <th>Date</th>

            </tr>

          </thead> 


        </table>


      </div>

    </div>

  </section>

</div>

这就是我随AJAX带来的功能

<?php

    class SalesTable{

      /*=============================================
      SHOW SALES TABLE
      =============================================*/

      public function ShowTable(){  

        $sales = SalesController::ctrShowSales();

        $jsonDate = '{

         "data": [ ';

        for($i = 0; $i < count($sales); $i++){

            /*=============================================
            PRODUCT
            =============================================*/

            $item = "id";
            $value = $sales[$i]["id_product"];

            $myProduct = ProductsController::ctrShowProducts($item, $value);

            $product = $myProduct[0]["title"];

            /*=============================================
            CLIENT
            =============================================*/

            $item2 = "id";
            $value2 = $sales[$i]["id_usuario"];

            $myClient = UsersController::ctrShowUsers($item2, $value2);

            $client = $myClient["name"];

            /*=============================================
            EMAIL
            =============================================*/

            if($sales[$i]["email"] == ""){

                $email = $myClient["email"];

            }else{

                $email = $sales[$i]["email"];
            }

            /*=============================================
            JSON
            =============================================*/
            $jsonDate    .= '[
                            "'.($i+1).'",
                            "'.$product.'",
                            "'.$client.'",
                            "$ '.number_format($sales[$i]["price"],2).'",
                            "'.$email.'",
                            "'.$sales[$i]["address"].'",
                            "'.$sales[$i]["date"].'"    
                            ],';


        } 

        $jsonDate = substr($jsonDate, 0, -1);

        $jsonDate.=  ']

        }'; 

        echo $jsonDate; 

      }

    }

    $active = new SalesTable();
    $active -> ShowTable(); 

0 个答案:

没有答案