title: Trying to group TR rows by a common value
body: <p>I have "domains". The domains own "phone numbers". What I am trying to do is group all the numbers together with their associated domain. </p>
  
  <p>I'm getting lost in the logic in terms of how to know when one domain is done and another domain is now in the queue to know when to end one TR and start another so they can be grouped into their own background color or table. </p>
  
  <p>My code attempt: </p>
  
  <pre><code>$domainsqlquery = "SELECT DOMAIN FROM phone_numbers WHERE `RESELLER_ID` ='".$RID."'";
      if ($domainresult = mysqli_query($conn, $domainsqlquery)) {
          if (mysqli_num_rows($domainresult) &gt; 0) {
              while ($domainrow = mysqli_fetch_assoc($domainresult)) {
                  echo '&lt;tr'.(($c = !$c)?' class="odd"':' class="even"')."&gt;";
                  $sqlquery = "SELECT * FROM phone_numbers WHERE `RESELLER_ID` ='".$RID."' AND `DOMAIN` ='".$domainrow['DOMAIN']."'";
                  if ($result = mysqli_query($conn, $sqlquery)) {
                      if(mysqli_num_rows($result)&gt;0){
                          while ($row = mysqli_fetch_assoc($result)) {
                              echo "&lt;td&gt;";
                              echo "&lt;form action='' method='POST'&gt;";
                              echo "&lt;input name='R_number' value='".$row['NUMBER']."' type='hidden'&gt;";
                              echo "&lt;input name='N_ID' value='".$row['ID']."' type='hidden'&gt;";
                              echo $row['DOMAIN'] ." - ". $row['NUMBER'] ." - Cost: &lt;input name='R_cost' value=".$row['COST']." style='width:50px'&gt; &lt;input type='submit' name='btn-drop' value='X'&gt; &amp;nbsp; &lt;input type='submit' name='btn-update' value='UPDATE'&gt; &amp;nbsp;&amp;nbsp; &lt;a href=\"domain=".$row['DOMAIN']."&amp;caldate=04\" target='_blank'&gt;Open Report&lt;/a&gt;&lt;br&gt;";
                              echo "&lt;/form&gt;";
                              echo "&lt;/td&gt;";
                          }
                      }
                  }
                  echo "&lt;/tr&gt;";
              }
          }
  </code></pre>