title: PHP/mySQLi : Loop inside a loop doesn't return all results
body: <p>I'm basically in the process of designing a web front-end for a menu, I have created a system to add meals to the menu and now I need to read it to the user. I also need to organize things into categories (aka div's). To do so I wrote code that (I think) should get a list of categories (distinct results in a column), then get the names and prices of each meal for each category.</p>
  
  <p>The issue is that it is not displaying all the categories or meals.</p>
  
  <p>Here's my DB structure, ID is the primary index
  <img src="https://i.imgur.com/wc5CvjB.png" alt="db structure">
  My code looks like this,</p>
  
  <pre><code>        &lt;?php
          mysqli_report(MYSQLI_REPORT_ALL ^ MYSQLI_REPORT_INDEX);
          $db = new mysqli('localhost', 'username', 'password', 'db');
          if($db-&gt;connect_errno &gt; 0){
              die('Unable to connect to database [' . $db-&gt;connect_error . ']');
          }
  
          $query = "SELECT DISTINCT `mealtype` FROM `meals`";
          if(!$result = $db-&gt;query($query)){
              die('There was an error running the query [' . $db-&gt;error . ']');
              }
          else {
              $row = $result-&gt;fetch_assoc();
              while($row = $result-&gt;fetch_assoc()){
                  $mealtype=$row['mealtype'];
                  echo "&lt;div class='pure-u-1-3'&gt;&lt;h1&gt;".strtoupper($mealtype)."&lt;/h1&gt;";
                  $mealquery = "SELECT * from `meals` where `mealtype` = '".$mealtype."'";
                  $mealresult = $db-&gt;query($mealquery);
                  $mealrow = $result-&gt;fetch_assoc();
                  echo $db-&gt;error;
                  while($mealrow = $mealresult-&gt;fetch_assoc()){
                      echo "&lt;b&gt;".$mealrow['name']."&lt;/b&gt;".$mealrow['price'].'&lt;br&gt;';
                      }
                  echo "&lt;/div&gt;";
  
              }
  
          }
  
  
          $db-&gt;close();
  ?&gt;
  </code></pre>
  
  <p>I also noted that without mysqli_report(MYSQLI_REPORT_ALL ^ MYSQLI_REPORT_INDEX); I get a warning, but to my understanding this is due to the use of the DISTINCT selector.</p>
  
  <p>when Error reporting is fully activated it returns</p>
  
  <pre><code>PHP Fatal error:  Uncaught exception 'mysqli_sql_exception' with message 'No index used in query/prepared statement SELECT DISTINCT `mealtype` FROM `meals`' in (workingdir)/index.php:42
  </code></pre>
  
  <p>I'm at a complete loss as to why it won't display everything, I'm sure it's to do with the double loop, as when I just ask it to return the table in the menu manager it works fine.</p>
  
  <p>EDIT : The Issue turned out to be a 1D13T error, I should have payed more attention to my code. </p>