Jump to content

how can I improve this script???


mikefrederick

Recommended Posts

Check out scripts.loado.com/friendsearcher.php.

 

Type in University Wisconsin Madison (slow enough to let the search results populate while typing - slow server). After you type a space and then M for Madison, Wisconsin typically becomes unhighlighted.

The search box works, but not correctly all of the time. What you are searching for should be highlighted in the search results that show up, but sometimes words do not get highlighted until the entire word has been searched for, and sometimes they do not get highlighted at all, and sometimes they become unhighlighted as I just said above. I think it words better in Safari than Firefox. How should I improve this script to get rid of these annoying errors?

$bar = $_GET['letters'];
$bar = preg_replace("/[^a-z0-9 ]/si","",$bar);
$x=explode(" ",$bar);
$u=explode(" ",$bar);
$e=array($u);

$z="<span style='color: #000066; font-weight: 600'>" . implode(" </span><span style='color: #000066; font-weight: 600'>",$x) . "</span>";
$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($u as $x)
    $t= str_replace($x,"<span style='color: #000066; font-weight: 600'>" . $x . "</span>",$t);

	echo $inf["id"]."###".$t."|"; 
 }	

Link to comment
Share on other sites

here is the code I am using now, a little better but still not much, and in addition, sometimes the <span> will show up in the search box. example: type in "University Wisconsin Madison t". whyy

 

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 ";
$replacesz[1]=" ";
$replacess[0]=" ";
$bar=str_replace($replacee,$replacess,$bar);

$x=explode(" ",$bar);
$z="<span style='color: #000066; font-weight: 600'>" . implode(" </span><span style='color: #000066; font-weight: 600'>",$x) . "</span>";
$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 style='color:#000066'>" . $x . "</span>",$t);
echo $inf["id"]."###".$t."|"; 
 }	

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.