I'm making a PHP/MySQL(i) website application, and I am getting this dreaded error, "Commands out of sync; you can't run this command now".
I have a connection to a database.
(P.S. - This is different from all other questions with similar titles -- I have gone through them all. What I want to do is OPEN first query, CLOSE first query, then OPEN second query. I do not want to execute multiple statements at once, or open multiple result-sets simultaneously)
Here is what I am doing:
<?php
$sql = 'CALL spSelectProductAndVendor(1, 1)';
$rs = $mysqli->query($sql);
echo($mysqli->error);
if ($rs->num_rows > 0) {
while ($row=$rs->fetch_assoc()) {
echo '<h1 class="page-header">' . $row["productname"] . '<small> pertaining to vendor: ' . $row["vendorname"] . '</small></h1>';
}
}
$rs->close();
?>
HTML/CSS
<?php
$sql = 'CALL spSelectRecentDocumentScores();';
$rs = $mysqli->query($sql);
echo($mysqli->error);
if ($rs->num_rows > 0) {
while ($row=$rs->fetch_assoc()) {
if($row["totalwarnings"]>50) { echo '<tr class="danger">'; } else { echo '<tr class="active">'; }
?>
<td><a href="documentdetail.php?documentid=<?php echo $row["documentid"]; ?>" style="color:#000000"><?php echo $row["documentid"]; ?></a></td>
<td>etc...</td>
</tr>
<?php
}
}
?>
Why does this error only occur upon the SECOND call?
$rs = $mysqli->query($sql);
The first one works fine. The second does not. But I am closing the first $rs. So what is missing?