Execute code each time x <= y while looping
<p>I'm not exactly sure how to explain this but basically I have an x variable equal to the number of rows in a database and each time it is equal to 4 or less, run a piece of code.</p>

<p>So say I have 5 rows, I want to execute the code twice because x is equal to 4 once and then equal to 1. Same if I had 6 rows (4+2) 7 rows (4+3) or 8 rows (4+4).</p>

<p>Then, when I reached 9 rows (4+4+1), it would execute the code thrice. Etc...</p>

<p>The code I'm trying to run is a piece of HTML with some more PHP inside it. I want to create a new <code>&lt;ul&gt;</code> with the said code inside it each time the number of rows is equal to 4 or less as explained above.</p>

<p>The code as it is right now:</p>

<pre><code>&lt;div class="row-fluid well"&gt;
  &lt;?php
  $num_rows = mysql_num_rows($result);
  if ($num_rows &lt;= 4) {
    ?&gt;
    &lt;ul class="minigames"&gt;
    &lt;?php
    while ($row = mysql_fetch_array($result)) {
      echo "&lt;li class='span3'&gt;";
      if (logged_in() === false &amp;&amp; !empty($row['app_about']) === true &amp;&amp; strlen($row['app_about']) &lt;= 100) {
        echo "&lt;a href='#!' class='thumbnail minigamedesc' title='" . $row['app_name'] . "' data-content='" . $row['app_about'] . "&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a href=\"./games.php?play_error#library\" class=\"btn btn-info\"&gt;&lt;i class=\"icomoon-white icomoon-screen\"&gt;&lt;/i&gt; Play in browser&lt;/a&gt;&lt;/center&gt;'&gt;";
      } else if (logged_in() === false &amp;&amp; !empty($row['app_about']) === true &amp;&amp; strlen($row['app_about']) &gt;= 101) {
        $app_about = substr(strip_tags($row['app_about']), 0, 100);
        echo "&lt;a href='#!' class='thumbnail minigamedesc' title='" . $row['app_name'] . "' data-content='" . $app_about . "&lt;a href=\"./games.php?play_error#library\"&gt;...&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a href=\"./games.php?play_error#library\" class=\"btn btn-info\"&gt;&lt;i class=\"icomoon-white icomoon-screen\"&gt;&lt;/i&gt; Play in browser&lt;/a&gt;&lt;/center&gt;'&gt;";
      } else if (!empty($row['app_about']) === true &amp;&amp; strlen($row['app_about']) &lt;= 100) {
        echo "&lt;a href='#!' class='thumbnail minigamedesc' title='" . $row['app_name'] . "' data-content='" . $row['app_about'] . "&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a href=\"./play.php?app=" . $row['app_id'] . "\" class=\"btn btn-info\"&gt;&lt;i class=\"icomoon-white icomoon-screen\"&gt;&lt;/i&gt; Play in browser&lt;/a&gt;&lt;/center&gt;'&gt;";
      } else if (!empty($row['app_about']) === true &amp;&amp; strlen($row['app_about']) &gt;= 101) {
        $app_about = substr(strip_tags($row['app_about']), 0, 100);
        echo "&lt;a href='#!' class='thumbnail minigamedesc' title='" . $row['app_name'] . "' data-content='" . $app_about . "&lt;a href=\"./play.php?app=" . $row['app_id'] . "\"&gt;...&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a href=\"./play.php?app=" . $row['app_id'] . "\" class=\"btn btn-info\"&gt;&lt;i class=\"icomoon-white icomoon-screen\"&gt;&lt;/i&gt; Play in browser&lt;/a&gt;&lt;/center&gt;'&gt;";
      } else {
        echo "&lt;a href='#!' class='thumbnail minigamedesc' title='" . $row['app_name'] . "' data-content='Nothing to see here, yet ! &lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a href=\"./play.php?app=" . $row['app_id'] . "\" class=\"btn btn-info\"&gt;&lt;i class=\"icomoon-white icomoon-screen\"&gt;&lt;/i&gt; Play in browser&lt;/a&gt;&lt;/center&gt;'&gt;";
      }
      ?&gt;
      &lt;img src="&lt;?php echo $row['app_preview']; ?&gt;"&gt;
      &lt;div class="minigames-caption"&gt;
        &lt;h4&gt;&lt;?php echo $row['app_name']; ?&gt;&lt;/h4&gt;
        &lt;p&gt;By &lt;?php echo $row['app_dev']; ?&gt;.&lt;/p&gt;
      &lt;/div&gt;
      &lt;/a&gt;
      &lt;?php
      echo "&lt;/li&gt;";
    }
      ?&gt;
  &lt;?php
  }
  ?&gt;
</code></pre>

<p>
</p>
