我想知道如何执行像这样的两个不同的查询:
if ($uresult->num_rows >0) {
while($urow = $uresult->fetch_assoc()) {
$rresult = mysqli_query($con,"SELECT * FROM allid WHERE postid='$oldid' AND spaceid='$newid'");
$rresult = mysqli_query($con,"DELETE FROM allid WHERE postid AND spaceid IS NULL");
$lrow = mysqli_fetch_assoc($rresult);
$tem = $lrow['postid'];
$ujson = json_encode($tem);
echo $ujson;
}
} else {
}
我知道mysqli_fetch
最多只能包含一个查询,而且还有类似的问题,但我似乎无法理解其他问题的答案。如果有一个问题解决了这个问题,我道歉,并将删除这个问题。
发布于 2018-05-29 07:15:25
在其他条件相同的情况下,简单地不要用delete覆盖select中的$rresult
:
if ($uresult->num_rows >0) {
while($urow = $uresult->fetch_assoc()) {
$rresult = mysqli_query($con,"SELECT *
FROM allid
WHERE postid='$oldid'
AND spaceid='$newid'");
mysqli_query($con,"DELETE FROM allid
WHERE postid AND spaceid IS NULL");
$lrow = mysqli_fetch_assoc($rresult);
$tem = $lrow['postid'];
$ujson = json_encode($tem);
echo $ujson;
}
} else {
}
发布于 2018-05-29 07:16:47
如果有多个查询依赖于上一个查询的结果,或者需要按顺序运行,并且每个查询都成功运行,则可以使用事务。对于事务,如果其中一个查询失败,您可以回滚该事务。
https://stackoverflow.com/questions/50574372
复制相似问题