I am getting some data from the mysql through a select.
$result = mysqli_query($cxn, $query);
I then go through it with
if ($result!= false) {
while ($row = mysqli_fetch_assoc($result)) {
do_stuff();
}
}
What I’d like to do is to add a line before the while ONLY if there is more than one line in the $result.
I understand that I could create an array of $row‘s first and then count them, but that would defeat the convenience of the while.
Question: is there a way to find out how many rows the mysqli_fetch_assoc would generate without running it twice?
You should check this function: http://php.net/mysqli_num_rows
You can check the number of results by using it like this