gpt4 book ai didi

php - 无组织的表

转载 作者:行者123 更新时间:2023-11-29 12:25:58 24 4
gpt4 key购买 nike

我需要 table 方面的帮助。它们没有组织/整齐并且非常困惑 -> http://i.imgur.com/1LLpQ2G.png

表格必须看起来整洁、易于理解并且不会像这样困惑 -> http://i.imgur.com/R3iqFzz.png (这就是表格的样子)

这是我迄今为止所取得的成就(参见: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>

请大家帮忙。

最佳答案

  1. 首先从数据库获取客户
  2. 对于每个客户,按 customerID 与 ordermenu(在 ordermenu.OrderID = order.OrderID)连接并与 menu(在 ordermenu.MenuID = menu.MenuID)连接的方式获取订单

    <?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
    }
    }

关于php - 无组织的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28311728/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com