title: Combining two SQL queries to a array?
body: <p>Is this the correct way to combine two SQL queries to a array?</p>
  
  <p>Note: I am aware of SQL JOIN, but I need to use two querys. </p>
  
  <p>See below:</p>
  
  <pre><code>    $query = "SELECT  * FROM categories WHERE takeawayID  = :TakeawayID";
      $statement = $this-&gt;db-&gt;prepare($query);
      $statement-&gt;bindValue(':TakeawayID', $takeawayID, PDO::PARAM_STR);
      $statement-&gt;execute();
      $data['rowCats'] = $statement-&gt;fetchall(PDO::FETCH_CLASS);
      $categories = array();
      foreach ($data['rowCats'] as $cat) {
          $temp_categories = array();
          $temp_categories['id'] = $cat-&gt;id;
          $temp_categories['name'] = $cat-&gt;name;
  
          $num = $cat-&gt;id;
  
          $query = "SELECT * FROM items WHERE category_id = :category_id";
          $statement = $this-&gt;db-&gt;prepare($query);
          $statement-&gt;bindValue(':category_id', $num, PDO::PARAM_STR);
          $statement-&gt;execute();
          $data['rowItem'] = $statement-&gt;fetchall(PDO::FETCH_CLASS);
          foreach ($data['rowItem'] as $Item) {
             $temp_categories['item']['name'][] = $Item-&gt;name;
          }
                         $categories[] = $temp_categories;
      }
  </code></pre>
  
  <p>$categories array is now can be pass on to view file (template)</p>
  
  <p>In the view file I should be able to do something like this:</p>
  
  <pre><code>&lt;?php foreach($categories as $category): ?&gt;
      &lt;table  border=0 Cellspacing='0'&gt;
          &lt;tr&gt;
              &lt;td&gt;
                &lt;?php echo $category['name']; ?&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;?php foreach ($category['items'] as $item): ?&gt;     
          &lt;tr&gt;
              &lt;td&gt;
                &lt;?php echo $item['name']; ?&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;?php endforeach; ?&gt;
      &lt;/table&gt;
  &lt;?php endforeach; ?&gt;
  </code></pre>