title: PHP Array vs MYSQL Queries speed optimization
body: <p>I'm trying to make my php mysql driven pages as fast as possible.
  I've got a fairly standard website with a left-column menu with lists of articles and recipes (loaded from the db) and then on the main content there are some randomly changing articles with clipped previews and also random recipes.</p>
  
  <p>What I've got at the moment is one sql query which loads all the articles and recipes into a php array that looks like this:</p>
  
  <pre><code>$s = s("SELECT * FROM `pages` WHERE `visible`='1' ORDER BY `group` ASC, `date` DESC");
     while($r=mysql_fetch_assoc($s)) $hPage[]=$r;
     $hPage_count = count($hPage);
     $hPage_keys = array_keys($hPage);
     $hPage_size = sizeOf($hPage_keys);
  </code></pre>
  
  <p>Then I simply refer back to and search this array for all the data I need for different parts of my page.</p>
  
  <p>One of my loops looks something like</p>
  
  <pre><code>for ($i=0; $i&lt;$hPage_size; $i++){
  $c = $hPage[$hPage_keys[$i]];
  if($c['group']==1){
  $type[$c['type']][count($type[$c['type']])] = array('title'=&gt;$c['title'],'url'=&gt;$c['url']);
  }
  }
  </code></pre>
  
  <p>What I need to find out is, is this the fastest way to do it? With only one SQL query, loading everything into a php array and then working with that, Or would it be better to make multiple SQL queries?</p>
  
  <p>Thanks for any help.</p>