我需要桌子的帮助。他们没有组织/整洁,非常混乱->

表格必须看起来整洁,易于理解且不会造成混淆--(这就是表格的样子)

这是我到目前为止已经实现的(请参阅:OrderID 2)-> http://i.imgur.com/fj06EGB.png

下面是代码

<table>
            <tr>
                <th>Customer Name</th>
                <th>Customer Contact</th>
                <th>Customer Email</th>
                <th>Order ID</th>
                <th>Order Date</th>
                <th>Menu Name</th>
                <th>Price</th>
                <th>Quantity</th>
                <th>Total Amount</th>
                <th>Action</th>
            </tr>
        <?php
            $result = $mysqli->query("SELECT * FROM `order`");
            while($obj = mysqli_fetch_assoc($result)) {
                $orderDate = $obj['OrderDate'];
                $orderId = $obj['OrderID'];
                $totalAmount = $obj['OrderTotal'];
                $paymentStatus = $obj['PaymentStatus'];
                $customerId = $obj['CustomerID'];
                $res = $mysqli->query("SELECT CustomerName, CustomerContactNo, CustomerEmail FROM customer WHERE CustomerID=$customerId");
                if($row = mysqli_fetch_assoc($res)) {
                    $customerName = $row['CustomerName'];
                    $customerContactNo = $row['CustomerContactNo'];
                    $email = $row['CustomerEmail'];
                }

                $result1 = $mysqli->query("SELECT * FROM ordermenu WHERE OrderID = $orderId");
                while($obj1 = mysqli_fetch_assoc($result1)) {
                    $menuId = $obj1['MenuID'];
                    $menuQty = $obj1['menuQty'];
                    $result2 = $mysqli->query("SELECT * FROM menu WHERE MenuID = $menuId");
                    $obj2 = mysqli_fetch_assoc($result2);
                    $name = $obj2['MenuName'];
                    $price = $obj2['MenuPrice'];
                ?>


            <tr>
                <td><?php echo $customerName;?></td>
                <td><?php echo $customerContactNo;?></td>
                <td><?php echo $email;?></td>
                <td><?php echo $orderId;?></td>
                <td><?php echo $orderDate;?></td>
                <td><?php echo $name;?></td>
                <td>$<?php echo $price;?></td>
                <td><?php echo $menuQty;?></td>
                <td>$<?php echo $totalAmount;?></td>
                <td><a href="update_order.php?id=<?php echo $orderId;?>" color="green">Update</a></td>
            </tr>

                <?php } ?>
            <?php } ?>
        </table>


任何人请帮助。

最佳答案

首先从数据库获得客户
Foreach客户通过customerID获取与ordermenu(在ordermenu.OrderID = order.OrderID上)并与菜单(在ordermenu.MenuID = menu.MenuID上)结合的Orders

<?php
$customerQuery = $mysqli->query("SELECT CustomerID, CustomerName, CustomerContactNo, CustomerEmail FROM customer;");
while($customer = mysqli_fetch_assoc($customerQuery)) {
    $customerId = $customer['CustomerID'];
    $orderQuery = $mysqli->query("SELECT * FROM `order` o LEFT JOIN ordermenu om ON o.OrderID = om.OrderID LEFT JOIN menu m ON m.MenuID = om.MenuID WHERE o.CustomerID = $customerId");
    while($order = mysqli_fetch_assoc($orderQuery)) {
        // do something with your customer and order record
        // show in table for example
    }
}

10-06 03:03