加入2表添加另一个表,销售总额

时间:2018-04-05 03:19:16

标签: php

如何在我的表格中添加购买项目的总成本? 我想在销售总额中添加另一行,即向供应商购买特定商品的用户。

sales_detail表。

enter image description here

销售表。

enter image description here

我要添加总价格的示例照片 这将是一个很大的帮助,谢谢你们!

这是我的php文件。

 <h1 class="page-header">Product Sales Report</h1></center>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <center>
 <form action="total_sales.php" method="post">
  From: <input type="text" class="datepicker" placeholder="E.G.(2018-01-14)" name="dayfrom" required pattern="[0-9]{4}+[0-9]+[0-9]"> To: <input type="text" class="datepicker" placeholder="E.G.(2018-02-11)" name="dayto" required pattern="[0-9]{4}+[0-9]+[0-9]">
  <input type="submit" value="Show Sales" name="salesbtn" ></form></center>

            <table width="100%" class="table table-striped table-bordered table-hover" id="prodTable">
                <thead>
                    <tr>
                        <th class="hidden"></th>
                        <th>Purchase Date</th>
                        <th>Customer</th>
                        <th>Product Name</th>
                        <th>Quantity</th>
                    </tr>
                </thead>
                <tbody>
                <?php
                    $sq=mysqli_query($conn,"select * from sales_detail left join product on product.productid=sales_detail.productid left join sales on sales.salesid=sales_detail.salesid left join customer on sales.userid=customer.userid where product.supplierid='".$_SESSION['id']."' order by sales.sales_date desc");;
                    while($sqrow=mysqli_fetch_array($sq)){

                    ?>
                        <tr>
                            <td class="hidden"></td>
                            <td><?php echo date('M d, Y h:i A',strtotime($sqrow['sales_date'])); ?></td>
                            <td><?php echo $sqrow['customer_name']; ?></td>
                            <td><?php echo $sqrow['product_name']; ?></td>
                            <td><?php echo $sqrow['sales_qty']; ?></td>
                        </tr>
                    <?php
                    }
                ?>
                </tbody>
            </table>
        </div>
    </div>

1 个答案:

答案 0 :(得分:1)

我在while循环中添加了一个条件语句,以输出特定产品用户的销售总额。

更新代码:

<h1 class="page-header">Product Sales Report</h1></center>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <center>
 <form action="total_sales.php" method="post">
  From: <input type="text" class="datepicker" placeholder="E.G.(2018-01-14)" name="dayfrom" required pattern="[0-9]{4}+[0-9]+[0-9]"> To: <input type="text" class="datepicker" placeholder="E.G.(2018-02-11)" name="dayto" required pattern="[0-9]{4}+[0-9]+[0-9]">
  <input type="submit" value="Show Sales" name="salesbtn" ></form></center>

            <table width="100%" class="table table-striped table-bordered table-hover" id="prodTable">
                <thead>
                    <tr>
                        <th class="hidden"></th>
                        <th>Purchase Date</th>
                        <th>Customer</th>
                        <th>Product Name</th>
                        <th>Quantity</th>
                    </tr>
                </thead>
                <tbody>
                <?php
                    $sales_total_id = array();

                    $sq=mysqli_query($conn,"select * from sales_detail left join product on product.productid=sales_detail.productid left join sales on sales.salesid=sales_detail.salesid left join customer on sales.userid=customer.userid where product.supplierid='".$_SESSION['id']."' order by sales.sales_date desc");
                    while($sqrow=mysqli_fetch_array($sq)){
                        if( !isset( $sales_total_id[$sqrow['salesid']] ) ) {
                            $sales_total_id[$sqrow['salesid']] = TRUE;
                            ?>
                            <tr>
                            <td colspan="5" align="center"><strong>Sales Total: <?php echo $sqrow['sales_total']; ?></strong></td> 
                            </tr>
                            <?php
                        }
                    ?>
                        <tr>
                            <td class="hidden"></td>
                            <td><?php echo date('M d, Y h:i A',strtotime($sqrow['sales_date'])); ?></td>
                            <td><?php echo $sqrow['customer_name']; ?></td>
                            <td><?php echo $sqrow['product_name']; ?></td>
                            <td><?php echo $sqrow['sales_qty']; ?></td>
                        </tr>
                    <?php
                    }
                ?>
                </tbody>
            </table>
        </div>
    </div>
相关问题