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
https://forums.phpfreaks.com/topic/91114-how-can-i-improve-this-script/
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."|"; 
 }	

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.