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
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

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.