title: How to loop multiple SELECT separately
body: <p>I have two queries for which i want to get result in separate while loop, query is working fine but i cant figure out how to get result separated in while loop.</p>
  
  <p><strong>php</strong></p>
  
  <pre><code>$query = "
  SELECT 1 as query, title FROM $tablename WHERE category='category1' LIMIT 10
  UNION
  SELECT 2 as query, title FROM $tablename WHERE category='category2' LIMIT 10
  ";
  
  $result = mysqli_query($connection, $query) or trigger_error(mysqli_error($connection), E_USER_ERROR);
  
  while($row = mysqli_fetch_assoc($result[1])){
      echo $row['title'].'&lt;br /&gt;';
  }
  while($row = mysqli_fetch_assoc($result[2])){
      echo $row['title'].'&lt;br /&gt;';
  }
  </code></pre>
  
  <p>Please see and suggest any possible way to do this.</p>