<?php SESSION_start(); if (!isset($_SESSION['m'])) { header("Location:logout.php"); } $cat = $_GET['cat']; $pro = $_GET['pro']; $bd = $_GET['bd']; $ed = $_GET['ed']; $con = mysqli_connect("localhost", "root", "123456", "hw3"); if (!$con) { die('database connection failed'); } if (strlen($cat) == 0 && strlen($pro) == 0) { if (strlen($bd) == 0 && strlen($ed) == 0) { $sql = "select sum(ProductQty) as TotalQty,ProductID from OrderDetail group by ProductID Order" . " by TotalQty DESC"; } else { $sql = "select sum(ProductQty) as TotalQty,ProductID from OrderDetail inner join OrderInfor where OrderDetail.OrderID" . "=OrderInfor.OrderID and OrderDate>='{$bd}' and OrderDate<='{$ed}' group by ProductID Order" . " by TotalQty DESC"; } $res = mysqli_query($con, $sql); echo '<table>'; $t = 0; echo mysqli_error($con); while ($row = mysqli_fetch_array($res)) { $pid = $row['ProductID']; $sql1 = "select * from Product where ProductID={$pid}"; $res1 = mysqli_query($con, $sql1); $row1 = mysqli_fetch_array($res1); $pro = $row1['ProductName']; echo '<tr><td>' . $pro . '    </td><td>Qty' . $row['TotalQty'] . '</td></tr>';
function logout() { SESSION_start(); SESSION_destroy(); header("Location:/CI/index.php/shopping/homepage"); }