mikefrederick Posted February 13, 2008 Share Posted February 13, 2008 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 More sharing options...
Bauer418 Posted February 13, 2008 Share Posted February 13, 2008 $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 https://forums.phpfreaks.com/topic/90907-search-help-interesting/#findComment-465963 Share on other sites More sharing options...
mikefrederick Posted February 13, 2008 Author Share Posted February 13, 2008 That's not working out for me. Is there a better way? I don't see what is wrong with what you wrote but all well Link to comment https://forums.phpfreaks.com/topic/90907-search-help-interesting/#findComment-466005 Share on other sites More sharing options...
Bauer418 Posted February 13, 2008 Share Posted February 13, 2008 Can you echo $query and any error that may be occurring? Link to comment https://forums.phpfreaks.com/topic/90907-search-help-interesting/#findComment-466008 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.