Jump to content

search help!! (interesting?)


mikefrederick

Recommended Posts

I made a search script like that of facebooks friend searcher. It is at scripts.loado.com/friendsearcher.php. Only difference is facebook uses a space (" ") separator when searching strings from a database. With mine, if you type a space and continue searching it will continue to search the same string (so basically my problem is that if you have a friend named Michael Frederick and you search for Frederick Michael it will not work. Frederick, Michael, or Michael Frederick will work) . I guess after the first space, I have to select from the database where I have already selected PLUS where name like %second explode($string)%...sorry if this is confusing, I know what has to be done I have just been confusing myself on how to do it. Here is how I am selecting from the database now, and thanks for the help:

 

 

$x = $_GET['x'];
$x = preg_replace("/[^a-z0-9 ]/si","",$x);
$res = mysql_query("select * from schools where name like '%".$x."%' order by name limit 7") or die(mysql_error());
while($inf = mysql_fetch_array($res)){
$t=$inf["name"];
$a=str_replace($x,"<span style='color: #000066; font-weight: 500'>$x</span>",$t);
	echo $inf["id"]."###".$a."|";
}	

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/90907-search-help-interesting/
Share on other sites

$x = $_GET['x'];
$x = preg_replace("/[^a-z0-9\s]/is", "", $x);
$x = explode(" ", $x);
$search = "WHERE name LIKE '%" . implode("%' OR name LIKE '%", $x) . "%'";
$query = "SELECT * FROM schools " . $search . " ORDER BY NAME ASC LIMIT 7";

// Query your DB and continue with your script

There are some more efficient ways of doing it, because there's a certain point where fulltext searching is better than 30 "OR LIKE..." clauses

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.