无法生成报告

时间:2018-07-10 10:31:09

标签: php report generate

我想生成单击并从类别下拉列表中选择的报告,然后它将显示您选择的类别中的哪种产品以及售出的数量的顺序。但是它无法显示出来,我发现了很多次错误,并且还尝试了SQL查询,因为它显示正确。我不知道为什么请帮助我。

<?php
    session_start();
    include_once 'header_admin.php';
    ?>

<div class="report">
    <h2>Sales Report</h2>
    <div class="sales_report">
        <form action="" method="POST">
            <select name="category" class="category">
                <option>Category</option>
                <?php
                include_once 'includes/dbh.php';
                $query1 = "SELECT * from category";
                $result1 = mysqli_query($conn, $query1);
                while ($row1 = mysqli_fetch_assoc($result1)) {
                    $CategoryID = $row1['CategoryID'];
                    $rowData1 = $row1['CategoryName'];
                    ?>
                    <option value="<?php echo $CategoryID; ?>"><?php echo $rowData1; ?></option>
                    <?php
                }
                ?>
            </select>
            <button class="generate" type="submit" name="generate">Generate</button>
            <table class="genreport">
                <tr>
                    <th>Furniture ID</th>
                    <th>Furniture Name</th>
                    <th>Category Name</th>
                    <th>Order Date</th>
                    <th>Quantity</th>
                    <th>Total Amount</th>
                </tr>                
                <?php
                if (isset($_POST['generate'])) {
                    $catName = mysqli_real_escape_string($conn, $_POST['category']);
                    $query2 = "SELECT D.FurCode, F.FurName, C.CategoryName, O.OrderDate, D.quantity, COUNT(D.quantity * D.PriceEach)
                               FROM orderdetail D, furniture F, category C, ordertab O 
                               WHERE C.CategoryName = '$catName' GROUP BY C.$catName ORDER BY C.$catName ";
                    $result2 = mysqli_query($conn, $query2);
                    if ($result2) {
                        while ($row2 = mysqli_fetch_array($result2)) {
                            $furCode = $row2['FurCode'];
                            $furName = $row2['FurName'];
                            $orderDate = $row2['OrderDate'];
                            $quantity = $row2['quantity'];
                            $priceEach = $row2['PriceEach'];
                            $total = $quantity * $priceEach;
                            ?>
                            <tr>
                                <td><?php echo $furCode; ?></td>
                                <td><?php echo $furName; ?></td>
                                <td><?php echo $catName; ?></td>
                                <td><?php echo $orderDate; ?></td>
                                <td><?php echo $quantity; ?></td>
                                <td><?php echo $total; ?></td>
                            </tr>

                            <?php
                        }
                    }
                } else {
                    echo '<tr><td>No Result!</td><td></td><td></td><td></td><td></td><td></td></tr>';
                }
                ?>
            </table>
        </form>
    </div>
</div>
</div>
</section>
</body>
</html>

0 个答案:

没有答案