0

I'm trying to get a page break after every five instances of the word "hello!"

I could obviously go on forever with the "||" method I'm using below, but that seems to be bad coding practice. What would be a better way to write this?

              $count = 0;
              while ($row = mysqli_fetch_assoc($results)) {
                echo "hello! "
                $count += 1;
                if ($count == 5 || $count == 10 || $count == 15 || $count == 20) {echo "<br>";}
sailingthoms
  • 900
  • 10
  • 22

1 Answers1

2

Use the modulo operator.

It checks if there is a remainder when dividing this by 5 (if it is divisible by 5):

if ($count % 5 == 0)
Cid
  • 14,968
  • 4
  • 30
  • 45
srv236
  • 509
  • 3
  • 5