2 回答
TA贡献1869条经验 获得超4个赞
要排除现有值,您可以尝试检查 null 来查找相应的匹配值
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
无论如何,你不应该在你的sql代码中使用php var,因为这样你就有sqlinjection的风险,为了避免这种情况,你应该看看准备好的语句和绑定参数
TA贡献1876条经验 获得超5个赞
这是很有可能做到的。按照我的逻辑。首先,您必须获取 food_cancel 表上的所有 food_id。然后将其保存到 variabel 中,并在显示 orderFood 表并添加 NOT IN 条件时使用它。
我已经为你写了代码
<?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 关注
- 108 浏览
添加回答
举报