jknelsonjk Posted April 19, 2011 Share Posted April 19, 2011 When I run this code it takes longer then I want to load the search results. I thought by only loading the first 30 rows it catches it would speed things up. Any ideas? I changed the $db to be 30, but only my first page painted and it was not much faster.... if(!empty($keyword) && $keyword!='Zip Code') $sql="SELECT profiles.*,zipCode FROM profiles LEFT JOIN area_served ON area_served.profileId = profiles.profileId WHERE profileType!='HO' AND profiles.status='Y' $qrystr GROUP BY profiles.profileId $orderby CASE zipCode $zips_order_str , companyName asc "; else $sql="SELECT * FROM profiles LEFT JOIN area_served ON area_served.profileId = profiles.profileId WHERE profileType!='HO' and status='Y' $qrystr GROUP BY profiles.profileId $orderby "; //echo $sql; $db->query($sql); $numRows=$db->numRows(); $page->set_page_data($_SERVER[php_SELF],$numRows,$listing,10,true,false,true); $page->set_qry_string("searchFor=$searchFor&cat=$cat&state=$state&keyword=$keyword&distance=$distance&sorting=$sorting&listing=$listing"); $res=$db->query($page->get_limit_query($sql)); $smarty->assign('numResult',$numRows); /* show pagination */ while($row=$db->fetchAssoc($res)) { if($row['thumbnailPhoto']=='personalPhoto' || $row['thumbnailPhoto']==''){ if(!empty($row['personalPhoto'])){ $personalPhoto="profiles/".$row['personalPhoto']; $rimg->setImage($personalPhoto); $row['personalPhoto']=$rimg->resize(75,75,substr($personalPhoto,0,strpos($personalPhoto,"."))."_search"); }else{ $row['personalPhoto']="images/my-photo.gif"; } }else{ if(!empty($row['logo'])){ $personalPhoto="profiles/".$row['logo']; $rimg->setImage($personalPhoto); $row['personalPhoto']=$rimg->resize(75,75,substr($personalPhoto,0,strpos($personalPhoto,"."))."_search"); }else{ $row['personalPhoto']="images/my-photo.gif"; } } if(count($cat>0)){ $row['cat']=@implode(", ",$cat); } if(strlen($row['companyInfo'])>90){ $concat="..."; } else{ $concat=""; } Quote Link to comment https://forums.phpfreaks.com/topic/234175-how-can-i-make-this-code-only-load-the-first-30-rows-or-run-faster-on-loading/ Share on other sites More sharing options...
requinix Posted April 19, 2011 Share Posted April 19, 2011 There's not nearly enough information to know why it seems slow to you. What's $db? What's $page? Is that stuff with $rimg actually resizing the image every single time? Quote Link to comment https://forums.phpfreaks.com/topic/234175-how-can-i-make-this-code-only-load-the-first-30-rows-or-run-faster-on-loading/#findComment-1203612 Share on other sites More sharing options...
mikosiko Posted April 19, 2011 Share Posted April 19, 2011 and expanding requinix questions: - Which is the size of tables profiles and area_served ? (row number) - Are they indexed?... which columns? Quote Link to comment https://forums.phpfreaks.com/topic/234175-how-can-i-make-this-code-only-load-the-first-30-rows-or-run-faster-on-loading/#findComment-1203621 Share on other sites More sharing options...
jknelsonjk Posted April 19, 2011 Author Share Posted April 19, 2011 The Profile table has ~240k rows. The Area table has only 41 Quote Link to comment https://forums.phpfreaks.com/topic/234175-how-can-i-make-this-code-only-load-the-first-30-rows-or-run-faster-on-loading/#findComment-1203631 Share on other sites More sharing options...
Maq Posted April 19, 2011 Share Posted April 19, 2011 In the future, please use tags around your code. Quote Link to comment https://forums.phpfreaks.com/topic/234175-how-can-i-make-this-code-only-load-the-first-30-rows-or-run-faster-on-loading/#findComment-1203634 Share on other sites More sharing options...
mikosiko Posted April 19, 2011 Share Posted April 19, 2011 look into the resizing of each record issue then as per requinix suggestion Quote Link to comment https://forums.phpfreaks.com/topic/234175-how-can-i-make-this-code-only-load-the-first-30-rows-or-run-faster-on-loading/#findComment-1203636 Share on other sites More sharing options...
The Little Guy Posted April 20, 2011 Share Posted April 20, 2011 if you have phpmyadmin, or mysql in a terminal, run the query using "explain" before each select. Example: explain select * from my_table where user_name='Mickey Mouse'; The columns you want to look at is: possible_keys and key if key returns null, you probably want to add some indexes to your table. so, I might index your first query like so: ALTER TABLE profiles ADD INDEX (profileType, status); Quote Link to comment https://forums.phpfreaks.com/topic/234175-how-can-i-make-this-code-only-load-the-first-30-rows-or-run-faster-on-loading/#findComment-1203827 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.