2 回答

TA貢獻(xiàn)1869條經(jīng)驗(yàn) 獲得超4個(gè)贊
要排除現(xiàn)有值,您可以嘗試檢查 null 來查找相應(yīng)的匹配值
SELECT *
FROM order_food of
LEFT JOIN foodcancel fc ON of.food_id = fc.food_id
and of.food_id = your_value
WHERE fc.orderfood_id is null
無論如何,你不應(yīng)該在你的sql代碼中使用php var,因?yàn)檫@樣你就有sqlinjection的風(fēng)險(xiǎn),為了避免這種情況,你應(yīng)該看看準(zhǔn)備好的語句和綁定參數(shù)

TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超5個(gè)贊
這是很有可能做到的。按照我的邏輯。首先,您必須獲取 food_cancel 表上的所有 food_id。然后將其保存到 variabel 中,并在顯示 orderFood 表并添加 NOT IN 條件時(shí)使用它。
我已經(jīng)為你寫了代碼
<?php
// Get Food Id From Cancel
$orderCancel = mysqli_query($mysqli, "SELECT * FROM `foodcancel`");
$cancelId = "";
while ($cancel = mysqli_fetch_array($orderCancel)) {
$cancelId .= $cancel["food_id"].",";
};
$cancelId = substr($cancelId, 0, -1);
// Put Food Id on Cancel Table into NOT IN Condition Database
$orderFood = mysqli_query($mysqli, "SELECT * FROM `orderfood` WHERE food_id NOT IN ($cancelId)");
while ($order = mysqli_fetch_assoc($orderFood)) {
$food[] = $order;
};
echo json_encode($food);
?>
- 2 回答
- 0 關(guān)注
- 151 瀏覽
添加回答
舉報(bào)