title: PHP MySQL query multiple products in multiple categories
body: <p>I want to output like this from the database:</p>
  
  <pre><code>Store name 1
  --------------------
  Product 1
  Product 2
  
  Store name 2
  ---------------------
  Product 3
  Product 4
  </code></pre>
  
  <p>and the query i use right now looks like this:</p>
  
  <pre><code>$query_stores = DB::query("SELECT * FROM `stores` LIMIT 16");
  
  foreach($query_stores as $row){
  
     echo $row['name'] . '&lt;br&gt;';
  
     $query_products = DB::query("SELECT `id`, `name` FROM `products` WHERE `vendor` = %i ORDER BY RAND() LIMIT 10" , $row['id']);
  
     foreach($query_products as $row2){
        echo $row2['name'] . '&lt;br&gt;';
     }
  }
  </code></pre>
  
  <p>The code works (sort of) but i can't filter the <code>stores</code> that don't have any items in the <code>products</code> table.</p>
  
  <p>Example output:</p>
  
  <pre><code>Store name 1
  
  Store name 2
      --------------------
      Product 1
      Product 2
  
  Store name 3
  
  Store name 4
      ---------------------
      Product 3
      Product 4
  
  Store name 5
  </code></pre>
  
  <p>Is there a better way to run the code? Can the two queries be combined?</p>
  
  <p>How to exclude the <code>stores</code> from output that don't have any items in the <code>products</code> table?</p>