title: Fetch all results MYSQL table - 6 items per row. If less than 6 results exist, list advert templates?
body: <p>I have a total of 8 results/users in my MYSQL table 'users'.</p>
  
  <p>I want to display 6 results/user profiles per row. This is what I'm currently getting as the result:</p>
  
  <pre><code>1st Result.   2nd Result.  3rd Result.  4th Result.   5th Result.  6th Result
  
  7th Result.   8th Result.    No More Results..... 
  </code></pre>
  
  <p>Not all users will have a profile image, so my code also checks for a profile image and if it can't find one it will use a template profile image instead.</p>
  
  <p>It is a requirement for each row to be complete with a minimum of 6 results/profiles. Where there is not enough results/profiles to complete a row, then I am trying to fill in the remaining non existent profiles with an advert template 'advertise your profile here'.</p>
  
  <p>The advert template image is stored in the following directory:</p>
  
  <pre><code>&lt;div&gt;&lt;img src="data/profile/0/main/advert.jpg" alt="Profile" height="100%" width="100%"&gt;&lt;/div&gt;';
  </code></pre>
  
  <p>This is my desired result:</p>
  
  <pre><code>1st Result.   2nd Result.  3rd Result.  4th Result.   5th Result.  6th Result
  
  7th Result.   8th Result.    9 Ad Here.  10 Ad Here.  11 Ad Here.  12 Ad Here.
  </code></pre>
  
  <p>Here is the code that I currently have.</p>
  
  <pre><code>   &lt;?php $sql = "SELECT * FROM users WHERE status = 'active' AND usertype = 'advertiser'";
          $result = $conn-&gt;query($sql)-&gt;fetch_all(MYSQLI_ASSOC);
  
  
          $limit = 6; 
          $chunks = array_chunk($result, $limit);
  
          foreach($chunks as $chunk){
          echo '&lt;div id="category_case_holder"&gt;';
  
          foreach($chunk as $chunkItem){
  
  
  
          $i = htmlspecialchars($chunkItem['user_id']);
          $filename = "data/profile/$i/main/profile.jpg"; 
          if (file_exists($filename)) {
          echo '&lt;div id="prime"&gt;&lt;a href="profile.php?id='.htmlspecialchars($chunkItem['user_id']).'"&gt;&lt;img src="data/profile/'.htmlspecialchars($chunkItem['user_id']).'/main/profile.jpg" alt="Profile" height="100%" width="100%"&gt;&lt;/a&gt;&lt;/div&gt;';
          }else{
          echo '&lt;div id="prime"&gt;&lt;a href="profile.php?id='.htmlspecialchars($chunkItem['user_id']).'"&gt;&lt;img src="data/profile/0/main/profile.jpg" alt="Profile" height="100%" width="100%"&gt;&lt;/a&gt;&lt;/div&gt;';
  
          } }
  
          echo '&lt;/div&gt;';
  
          } ?&gt; 
  </code></pre>
  
  <p>However, the code is still not giving the desired result. Please can someone help me improve/amend the code to get it to give me the result i require. Thank you.</p>