Jump to content

agh help (strings)


mikefrederick

Recommended Posts

Okay, have a script I am using to search a database. It searches correctly, separating each worth with a space (" "). However, I am also trying to replace the search query with a different color, and this only works up until the first space. After that, the search still works but nothing is replaced with a different color. Thanks in advance:

 

$bar = $_GET['letters'];
$bar = preg_replace("/[^a-z0-9 ]/si","",$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"];

$a=str_replace($bar,$z,$t);

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

 

 

$a=str_replace($bar,$z,$t); is the function used to replace the search query (I realize how incorrect I have this setup right now, I just held down apple+z for about a half hour undoing the different ways I have tried this).

Link to comment
https://forums.phpfreaks.com/topic/90937-agh-help-strings/
Share on other sites

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.