gpt4 book ai didi

php - MYSQL 查询结果重复

转载 作者:行者123 更新时间:2023-11-29 14:18:38 26 4
gpt4 key购买 nike

嗨,我有一个查询可以生成我需要的内容,但是我在输出中收到重复的行,并且无法弄清楚为什么,每行都出现两次。有什么想法吗?

$query = "SELECT * FROM orders LEFT JOIN users ON orders.USER_ID = users.USER_ID
LEFT JOIN items ON items.CHECKOUT_ID = orders.CHECKOUT_ID ORDER BY
date_order DESC LIMIT 0,1000";



$result = mysqli_query($con, $query);

while($row = mysqli_fetch_array($result, MYSQL_ASSOC)){
$order_id = $row["ORDER_ID"];
$date_order = $row["date_order"];
$date_req = $row["delivery"];
$country = $row["country"];
$firstname = $row["name"];
$lastname = $row["surname"];
$email = $row["email"];
$size = $row["size"];
$total_cost = $row["total_cost"];


echo '<tr><td>' . $order_id . ' </td>' .
'<td>' . $date_order . '</td>' .
'<td>' . $date_req . '</td>' .
'<td>' . $country . ' </td>' .
'<td>' . $firstname . ' </td>' .
'<td>' . $lastname . ' </td>' .
'<td>' . $email . ' </td>' .
'<td>' . $size . ' </td>' .
'<td>&euro;' . number_format($total_cost, 2, '.', '') . ' </td>' .
'<td style="text-align:right"><a href="xxxxxxx_Order_Details_Admin.php?id=' . $order_id . '">More Details</td>' .
'<td style="text-align:right"><a href="xxxxxxxx_Order_Details_print.php?id=' . $order_id . '">Print</td>' .

'</tr>';

最佳答案

您的查询应该为行中的每个项目返回一行。这是你所期待的吗?如果您期望每个用户一行或每个订单一行,那么您的查询是错误的。

从您正在撤出的字段中,我认为您不想要这些元素。请尝试以下查询:

SELECT *
FROM orders LEFT JOIN
user
ON orders.USER_ID = users.USER_ID
ORDER BY date_order DESC LIMIT 0,1000

如果您仍然收到重复项(或者当您期望每个项目一行时出现重复行),那么您需要查看基础表以查看重复项来自何处。

关于php - MYSQL 查询结果重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12158661/

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