Php MySQL-在不同的查询中执行Select和Delete?

Php MySQL-在不同的查询中执行Select和Delete?,php,mysql,mysqli,Php,Mysql,Mysqli,我想知道如何执行以下两个不同的查询: 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 all

我想知道如何执行以下两个不同的查询:

    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最多只能容纳一个查询,而且还有类似的问题,但我似乎无法理解其他问题的答案。如果有一个问题解决了这个问题,我很抱歉,并将删除这个问题。

在所有其他条件相同的情况下,请不要用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 {
}

如果有多个查询依赖于前一个查询的结果,或者需要按顺序运行,并且每个查询都成功运行,则可以使用事务。对于事务,如果其中一个查询失败,您可以回滚事务。

如果两个查询都使用$rresult,只需更改一个即可。。解决了您甚至不需要将delete-one分配给varOk的问题,我删除了变量,第二个查询没有从结果中删除null。安置重要吗@smith@LaneyWilliams你的意思是写postid为NULL,spaceid为NULL的地方吗?我相信是的,我刚刚测试过。下面是我得到的:10nullnull202您在选择后要删除,您的意思是用另一种方式吗?哦,不。我只想从上面的结果中删除这些null。我查了其他答案,他们说使用是空的。