mikefrederick Posted April 21, 2008 Share Posted April 21, 2008 i have a search script located at http://sites.loado.com/notestock/friendsearch.php You will see that if you slowly type in names of colleges that each letter will change colors, but if you don't do it slowly a lot of times if only does it every couple of letters and you will have typed in letters that don't change. This is my php code that the AJAX reaches for: <?php if(isset($_GET['getCountriesByLetters']) && isset($_GET['letters'])){ $bar = $_GET['letters']; $replace[0]="-"; $replace[1]="the "; $replaces[1]=""; $replaces[0]=""; $bar=str_replace($replace,$replaces,$bar); $replacee[0]=" of "; $replacee[1]=" in "; $replacess[1]=" "; $replacess[0]=" "; $bar=str_replace($replacee,$replacess,$bar); $x=explode(" ",$bar); $search = "WHERE name LIKE '%" . implode("%' and name LIKE '%", $x) . "%' "; $res=mysql_query("select * from schools " . $search . " order by name limit 7"); while($inf = mysql_fetch_array($res)){ $t=$inf["name"]; foreach(explode(" ",$bar) as $x) $t= str_replace($x,"<span class='searched'>" . $x . "</span>",$t); echo $inf["id"]."###".$t."|"; } } ?> any ideas on better optimization strategies? maybe it is dumb to add a span class to each letter Quote Link to comment Share on other sites More sharing options...
discomatt Posted April 21, 2008 Share Posted April 21, 2008 The more you can cache in the users browser, the better... If the entire XML-dump of your colleges is 25-50kb, then just load all results into javascript, and let the client do the matching. The nice part about real-time results is you don't have to be so loose in your searching. If a typo is made the user knows it instantly. If the xml dump is rather big, i recommend caching it to static xml pages x times a day using cron jobs.. Depending on the size, you can dump colleges starting with a-f in one file, g-m on another, or if that's too big a file for each starting letter. This way you save tons of unnecessary queries Let the client machine (JS) do the work Quote Link to comment 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.