title: PHP loop, separate results dependent on group_id
body: <p>I have a PHP loop going through my Media table, in the table they are these fields:
  id (unique id_, post_id (Random id per post), user_id, file_format, group_id</p>
  
  <p>If a group of multiple images are uploaded, they have a unique post_id, and have the same group_id, to distinguish between other groups of photos. However I can't figure out how to separate those groups inside the loop with an if statement to break up the div row.
  Here is my code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
    $sql = "SELECT * FROM media WHERE user_id = '".$_SESSION['user']."'";
    $result = $conn-&gt;query($sql);
    ?&gt;
    
    &lt;?php while($row = mysqli_fetch_array($result)):?&gt;
     &lt;?php $group_id = $row['group_id'] ?&gt;
    &lt;?php if($row['group_id'] == $group_id):?&gt;
     &lt;div class="card-group" style="color:black;"&gt;
       &lt;div class="card"&gt;
         &lt;img class="card-img-top" src="uploads/&lt;?=$row['post_id']?&gt;.&lt;?=$row['file_format']?&gt;" alt="Card image cap"&gt;
         &lt;div class="card-body"&gt;
           &lt;h4 class="card-title"&gt;Card title&lt;/h4&gt;
           &lt;p class="card-text"&gt;This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.&lt;/p&gt;
           &lt;p class="card-text"&gt;&lt;small class="text-muted"&gt;Last updated 3 mins ago&lt;/small&gt;&lt;/p&gt;
         &lt;/div&gt;
       &lt;/div&gt;
     &lt;/div&gt;
    &lt;?php endif;?&gt;
    &lt;?php endwhile;?&gt;</code></pre>
  </div>
  </div>
  </p>