我可以这样做来更新一行吗?这是我第一次使用 aLEFT JOIN
和UPDATE
.
UPDATE comments AS r
LEFT JOIN items AS i
ON i.items_id = r.item_id
LEFT JOIN master_cat AS c
ON c.cat_id = i.items_id
SET r.good = r.good + 1
WHERE i.item = '{$item}' AND c.category = '{$cat}' AND r.review = '{$review}';
它不会引发错误,但它会说 0 行受到影响,即使我已经确认我的变量可以使用正确的数据。(即使我对数据进行硬编码)。
编辑:我也尝试过内部连接,但也不起作用。
编辑 2:这实际上是我想要做的,我有这两个 queires,它们工作正常。我正在尝试将代码简化为一个。可以这样做:
// This query returns rate_id which I use as "$review_id" in the second query.
$query = "
SELECT r.rate_id
FROM comments as r
LEFT JOIN items AS i
ON i.items_id = r.item_id
LEFT JOIN master_cat AS c
ON c.cat_id = i.cat_id
WHERE r.review = '{$review}'
AND i.item = '{$item}'
AND c.category = '{$cat}';";
$query = "
UPDATE comments
SET good = good + 1
WHERE rate_id = '{$review_id}';";