More efficient way of doing this?

gerry.odea
Posts: 98
Joined: Fri Sep 19, 2008 9:33 am

More efficient way of doing this?

Post by gerry.odea »

<a name=REDIRECT>
<if $q eq "adsense"><header name=location value="http://adsense.google.com"></if>
<if $q eq "adwords"><header name=location value="http://adwords.google.com"></if>
<if $q eq "amazon"><header name=location value="http://www.amazon.com/gp/redirect.html? ... 9325"></if>
<if $q eq "amazon.com"><header name=location value="http://www.amazon.com/gp/redirect.html? ... 9325"></if>
<if $q eq "aol"><header name=location value="http://www.aol.com"></if>
<if $q eq "aol.com"><header name=location value="http://www.aol.com"></if>
<if $q eq "bing"><header name=location value="http://www.bing.com"></if>
<if $q eq "bing.com"><header name=location value="http://www.bing.com"></if>
<if $q eq "charter.net"><header name=location value="http://www.charter.net"></if>
<if $q eq "club penguin"><header name=location value="http://www.clubpenguin.com"></if>
<if $q eq "clubpenguin"><header name=location value="http://www.clubpenguin.com"></if>
<if $q eq "clubpenguin.com"><header name=location value="http://www.clubpenguin.com"></if>
<if $q eq "comcast.net"><header name=location value="http://www.comcast.net"></if>
<if $q eq "craigslist"><header name=location value="http://www.craigslist.com"></if>
<if $q eq "craigslist.com"><header name=location value="http://www.craigslist.com"></if>
<if $q eq "ebay"><header name=location value="http://www.ebay.com"></if>
<if $q eq "ebay.com"><header name=location value="http://www.ebay.com"></if>
<if $q eq "facebook"><header name=location value="http://www.facebook.com"></if>
<if $q eq "facebook login"><header name=location value="http://www.facebook.com"></if>
<if $q eq "FACEBOOK"><header name=location value="http://www.facebook.com"></if>
<if $q eq "Facebook"><header name=location value="http://www.facebook.com"></if>
<if $q eq "facebook.com"><header name=location value="http://www.facebook.com"></if>
<if $q eq "Facebook.com"><header name=location value="http://www.facebook.com"></if>
<if $q eq "FACEBOOK.COM"><header name=location value="http://www.facebook.com"></if>
<if $q eq "www.facebook.com"><header name=location value="http://www.facebook.com"></if>
<if $q eq "funbrain"><header name=location value="http://www.funbrain.com"></if>
<if $q eq "funbrain.com"><header name=location value="http://www.funbrain.com"></if>
<if $q eq "google"><header name=location value="http://www.google.com"></if>
<if $q eq "google.com"><header name=location value="http://www.google.com"></if>
<if $q eq "www.google.com"><header name=location value="http://www.google.com"></if>
<if $q eq "google maps"><header name=location value="http://maps.google.com"></if>
<if $q eq "google news"><header name=location value="http://news.google.com"></if>
<if $q eq "google videos"><header name=location value="http://video.google.com"></if>
<if $q eq "gmail"><header name=location value="http://www.gmail.com"></if>
<if $q eq "gmail.com"><header name=location value="http://www.gmail.com"></if>
<if $q eq "hotmail"><header name=location value="http://www.hotmail.com"></if>
<if $q eq "hotmail.com"><header name=location value="http://www.hotmail.com"></if>
<if $q eq "map quest"><header name=location value="http://www.mapquest.com"></if>
<if $q eq "mapquest"><header name=location value="http://www.mapquest.com"></if>
<if $q eq "mapquest.com"><header name=location value="http://www.mapquest.com"></if>
<if $q eq "www.mapquest.com"><header name=location value="http://www.mapquest.com"></if>
<if $q eq "www.miniclips.com"><header name=location value="http://www.miniclips.com"></if>
<if $q eq "www.miniclip.com"><header name=location value="http://www.miniclips.com"></if>
<if $q eq "msn"><header name=location value="http://www.msn.com"></if>
<if $q eq "msn.com"><header name=location value="http://www.msn.com"></if>
<if $q eq "myspace"><header name=location value="http://www.myspace.com"></if>
<if $q eq "MYSPACE"><header name=location value="http://www.myspace.com"></if>
<if $q eq "my space"><header name=location value="http://www.myspace.com"></if>
<if $q eq "myspace.com"><header name=location value="http://www.myspace.com"></if>
<if $q eq "Myspace.com"><header name=location value="http://www.myspace.com"></if>
<if $q eq "MYSPACE.COM"><header name=location value="http://www.myspace.com"></if>
<if $q eq "myspace."><header name=location value="http://www.myspace.com"></if>
<if $q eq "myspace .com"><header name=location value="http://www.myspace.com"></if>
<if $q eq "www.myspace.com"><header name=location value="http://www.myspace.com"></if>
<if $q eq "www myspace.com"><header name=location value="http://www.myspace.com"></if>
<if $q eq "neo pets"><header name=location value="http://www.neopets.com"></if>
<if $q eq "netflix"><header name=location value="http://www.netflix.com"></if>
<if $q eq "netflix.com"><header name=location value="http://www.netflix.com"></if>
<if $q eq "youtube"><header name=location value="http://www.youtube.com"></if>
<if $q eq "youtub"><header name=location value="http://www.youtube.com"></if>
<if $q eq "youtube.com"><header name=location value="http://www.youtube.com"></if>
<if $q eq "www.youtube.com"><header name=location value="http://www.youtube.com"></if>
<if $q eq "you tube"><header name=location value="http://www.youtube.com"></if>
<if $q eq "yo utube"><header name=location value="http://www.youtube.com"></if>
<if $q eq "yootube"><header name=location value="http://www.youtube.com"></if>
<if $q eq "u tube"><header name=location value="http://www.youtube.com"></if>
</a>

Also would a long long list like this slow down the script?

Thanks
User avatar
mark
Site Admin
Posts: 5519
Joined: Tue Apr 25, 2000 6:56 pm

More efficient way of doing this?

Post by mark »

Create a table with Key varchar(20),Location varchar(80)
and index on Key. Then do a select where Key=$q.

If you want to stick with a code version use <elseif>
or change to <switch $q>...<case "adsense">...
so you short circuit all of the following possibilities once you've found the match.
gerry.odea
Posts: 98
Joined: Fri Sep 19, 2008 9:33 am

More efficient way of doing this?

Post by gerry.odea »

Would using <switch> make it run faster? Also would using lots of <if>'s slow down the script?
User avatar
John
Site Admin
Posts: 2625
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH

More efficient way of doing this?

Post by John »

The <switch> will be a little faster than your ifs if there is a match, since it will stop looking once it finds a match. In any case a long list of ifs will slow down the script some. You'd need to time it to see exactly how big an impact that would have on your system.

An indexed table lookup will be faster with a long list of items.
John Turnbull
Thunderstone Software