Search code examples
phpwhile-loopcomparison

Comparison and $i++ in a while


I have a while loop while ($row = $result->fetch_assoc()) {$i++ }

And then I want to do something like:

if ($i == 5 && the total number of items is more than 10) {do this}

In other words, if the increment goes to 10+ then $i == 5 should do something else do nothing


Solution

  • https://www.php.net/manual/en/mysqli-result.num-rows.php

    if ($i == 5 && $result->num_rows > 10){do this}