DrTrans Posted October 16, 2009 Share Posted October 16, 2009 What im trying to do is this: #1. when someone goes to my site and types in a box " John Smith " it looks into the database under " fname, and lname" and displays all records with that name, or similar to that name. i also want them to be able to type jOhn smith. and it show up so it not be case sensitve. im sure it would be a sql statement. im just trying to get this working. Quote Link to comment https://forums.phpfreaks.com/topic/177984-solved-i-need-help-with-a-search/ Share on other sites More sharing options...
GoneNowBye Posted October 17, 2009 Share Posted October 17, 2009 First of all break the input into chunks. $data explode(" ",$string); will work $data[0] now = 'john' $data[1] now = 'smith' Now. Select * from database table where lname like '%$data[1]%' and fname like '%$data[0]%' The % mean anything so something% means any record where the field starts with something. good luck Quote Link to comment https://forums.phpfreaks.com/topic/177984-solved-i-need-help-with-a-search/#findComment-938434 Share on other sites More sharing options...
xtopolis Posted October 17, 2009 Share Posted October 17, 2009 Case sensitivity is based on the collation of your table. The default collation, latin1, is case insensitive. Alternatively, you can use a PHP function to set the input to lowercase before querying MySQL. Be careful if you choose to follow Havok's suggestion as using dual wildcards, one on each end, may produce unexpected results. Quote Link to comment https://forums.phpfreaks.com/topic/177984-solved-i-need-help-with-a-search/#findComment-938456 Share on other sites More sharing options...
DrTrans Posted October 17, 2009 Author Share Posted October 17, 2009 Heres my temp code if($submit) { $searchc = explode(" ",$search); $searchc[0]; $searchc[1]; $connect = mysql_connect("localhost","damgears_evil","damgears"); mysql_select_db("damgears_evil"); $query = mysql_query("SELECT * FROM titles WHERE fname LIKE '%$searchc[0]%'"); while($row = mysql_fetch_assoc($query)) { $dbid = $row['id']; $dbfname = $row['fname']; $dblname = $row['lname']; $dbkey = $row['key']; $dbskey = $row['skey']; $dbname = $row['sname']; $title = $row['title']; $dbstatus = $row['status']; $dbdate = $row['date']; $region = $row['region']; echo "$fname"; print "<center><b><a href=\"profile.php?fname=$dbfname&lname=$dblname\">$dbfname $dblname</a></b><br>"; } } However...in the datbase there could be John Smith <-- Same Person John Smith <-- Same Person John Sax John Alverez <-- John Alverez <-- would be the same person How do i get it to only state ( 1 ) of thenames and go on to the next one. so it reads : John Smith John Sax John Alverez Quote Link to comment https://forums.phpfreaks.com/topic/177984-solved-i-need-help-with-a-search/#findComment-938468 Share on other sites More sharing options...
DavidAM Posted October 17, 2009 Share Posted October 17, 2009 If the first and last name is all that you are interested in, the query would be: SELECT DISTINCT fname, lname FROM titles WHERE ... that will give you only rows where the combination is unique. If you want to summarize some of the other data, you could do something like: SELECT fname, lname, COUNT(title) as Articles FROM titles WHERE ... GROUP BY fname, lname which will return one row for each unique combination of first and last name along with a count of the number of titles associated with the combination. Quote Link to comment https://forums.phpfreaks.com/topic/177984-solved-i-need-help-with-a-search/#findComment-938483 Share on other sites More sharing options...
Kaboom Posted October 17, 2009 Share Posted October 17, 2009 use $_POST['search'] = strtolower($_POST['search']); to have it goto lowercase Quote Link to comment https://forums.phpfreaks.com/topic/177984-solved-i-need-help-with-a-search/#findComment-938524 Share on other sites More sharing options...
GoneNowBye Posted October 17, 2009 Share Posted October 17, 2009 i used like '%$data[0].... so on use or instead of and. Quote Link to comment https://forums.phpfreaks.com/topic/177984-solved-i-need-help-with-a-search/#findComment-938546 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.