PHP Array vs MYSQL Queries speed optimization

meyis

New Member
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.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:\[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\]Then I simply refer back to and search this array for all the data I need for different parts of my page.One of my loops looks something like\[code\]for ($i=0; $i<$hPage_size; $i++){$c = $hPage[$hPage_keys[$i]];if($c['group']==1){$type[$c['type']][count($type[$c['type']])] = array('title'=>$c['title'],'url'=>$c['url']);}}\[/code\]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?Thanks for any help.
 
Back
Top