PHP代码动态显示产品报告

问题描述 投票:0回答:1

我动我的POS软件的网络基础版本,一切都非常清楚,直到我想动态显示销售产品。

产品列表

enter image description here

销售表

enter image description here

我使用破灭插入我的记录时,我炸它工作得很好。

这里的问题是,我想,以显示产品即所有的销售基地销售表爆炸的product_id和使用每个ID来获得产品的名称。

同时爆炸的数量,并添加所有的数量一起立足于产品ID,并发生爆炸实际价格并显示等。

什么我得到这不是我想要的

enter image description here

这就是我要的

enter image description here

 <table id="salestable" class="table table-bordered table-striped table-hover">
                    <thead>
                      <tr class="titlerow" role="row">
                      <th >Products</th>
                      <th >Sold</th>
                      <th >Cost</th>
                      <th >Income</th>
                      <th >Profit</th>  
                      </tr>
                    </thead>
                    <tbody id="get_product">
                 <?php
                 try{       
    $query = $con->prepare("Select  s.product_id, s.adjust_price, s.real_price, s.quantity,  s.sales_date from tbl_sales s where s.status ='Paid' and  s.store_id = '$store'");
    $query->execute();
    while($row = $query->fetch(PDO::FETCH_ASSOC)){
        ?>      
            <tr>
            <td ><?php foreach(explode("|", $row['product_id']) as  $pID){ get_product_by_id($con, $pID); } ?></td>
            <td ><?php foreach(explode("|", $row['quantity']) as  $qty){ echo $qty; } ?></td>
            <td ><?php foreach(explode("|", $row['real_price']) as  $cost){ echo $cost; } ?></td>
            <td ><?php foreach(explode("|", $row['adjust_price']) as  $income){ echo $income; } ?></td>
            <td ><?php echo '2'; ?></td>
            </tr><?php


                                }                                


    } catch (PDOException $e){
                $_SESSION['error'] = $e->getMessage();
                $log = date('Y-m-d H:m:s').' '.$_SERVER['REQUEST_URI'].' '.$e->getMessage(). "\r\n";
            file_put_contents('../errorlog.txt', $log, FILE_APPEND);
}
                    ?>   </tbody>
                    <tfoot>
                      <tr class="totalColumn">
                        <th >Products</th>
                      <th class="totalCol" >Sold</th>
                      <th class="totalCol" >Cost</th>
                      <th class="totalCol" >Income</th>
                      <th class="totalCol" >Profit</th>
                      </tr>
                      <tr class="footersearch">
<td colspan="8" ><input type="text" class="form-control" name="search_table" id="search_table" title="Type & hit enter to search the table" data-toggle="tooltip" placeholder="Type & hit enter to search the table" style="width:100%;"></td>
</tr>
                    </tfoot>
                  </table>
php pdo
1个回答
0
投票

扩大对@熙德的评论上面,如果你不明白他的意思正常化什么。

如果你想出售或发票链接到一个客户,你需要一个客户表和发票表。如果你不想跟上客户的信息,只需要使用发票表。链接出售给发票项目的一种方法是用如下称为ProductInInvoice关系。这个伪不是有效的SQL,但你会得到的想法。

Products (
  productId,
  name,
  description,
  price,
  ...
);

Invoice (
  invoiceId
);

ProductInInvoice (
  productId,
  invoiceId,
  quantitySold
);

在这里,productId在ProductInInvoice表的外键进入产品表,invoiceId是一个外键的发票表。

如果你有一个客户表与customerId列来存储客户信息,你可以一个外键customerId添加到指客户表中的发票表。然后,你可以查询到发现不仅多少每个项目在该交易被出售,而且谁买了他们,通过在SELECT语句中连接表。

© www.soinside.com 2019 - 2024. All rights reserved.