probably a stupid question. I have the following code:
while ($stmt -> fetch()) {
echo "<p><strong>" .$name. "</strong><br />" .$comment. "</p>";
}
I would like to execute the while ONLY if $stmt -> fetch() returns at least one row (this is a SELECT query).. but if I do
if ($stmt -> fetch())
It gets executed already one time, and I want to avoid this. Any clue?
Thanks in advance.
http://php.net/manual/en/mysqli-stmt.num-rows.php
Try using
$stmt->num_rows > 0why
mysqli_resulthas afetchAllfunction andmysqli_stmtdoesnt…. i have no idea.Longer, but may work