I was wondering how would go about executing two different queries like this:
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 {
}
I know mysqli_fetch
can't hold no more than one query and there are similar questions, but I can't seem to understand the answers from the other questions. If there is a question that solves this question, I apologize and will delete this one.
all other things being equal, simple dont overwrite the $rresult
from select with delete:
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 {
}
If you have multiple queries that either rely on a result of a previous query or need to be run in order and each successfully run, you could use transactions. With transactions if one of the queries fails, you can roll back the transaction.