因此,在下面的查询中,我通过 order_id 连接两个表并显示 user_orders 表中的所有值。
根据下图,我尝试仅显示与 order_manager 表匹配的 order_Id 行。
public function getUserOrder(){
$sql = "SELECT user_orders.order_id,
user_orders.title, user_orders.price,
user_orders.quantity
FROM order_manager
JOIN user_orders ON order_manager.order_id = user_orders.order_id;";
$stmt = $this->connect()->prepare($sql);
$stmt->execute();
while ($result = $stmt->fetchAll()){
return $result;
}
}
我尝试使用一个 if 语句,该语句似乎可以执行某些操作,但它给出的值与反向订单 ID 不匹配。
getOrder(); foreach ($artworks->getOrder() as $art) { echo " Order ID Full Name Phone Address Orders "; } ?> $art[order_id] $art[full_name] $art[phone] $art[address]
Order ID title price Quantity "; $artworks->getUserOrder(); foreach ($artworks->getUserOrder() as $order) { if ($order['order_id'] == $art['order_id']) { echo " "; } echo "$order[order_id] "; } echo "$order[title] $order[price] $order[quantity]
这是一张图像来帮助解释所需的输出
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
解决了将 td 项目移动到 if 语句中的问题。我猜这基本上是正确的。
$artworks->getUserOrder(); foreach($artworks->getUserOrder() as $order) { if ($order['order_id'] == $art['order_id']) { echo "$order[order_id] ";
echo "
$order[title]
$order[price]
$order[quantity]
";
}
}