Equilibrium Posted January 16, 2010 Share Posted January 16, 2010 Hello everyone. I am new to php, I need to write a script for my website. I have a mysql database with a table in it. That table has five fields in it. I want to make an advanced search script with 5 text input box for the five different fields, so that the result with the common input in the fields will be shown. The searching script shouldbe like this: Firstly the keyword which will be typed in the first text box, the script should search that keyword in the first field and will keep the result in mind then it will check for the second input text box for any keywords, if there is any keywords then it will search that keyword in the second field of the table only.....like that this process will carryon for all those 5 fields. And at last it will show the common result only. What is this type of searching known as? What I have to do for making the script of this type of searching? Searchbox: --------------------------------------------------------------------------------------------------- | Text input for 1st field | Text input for 2nd field 3rd field | 4th field | 5th field | --------------------------------------------------------------------------------------------------- My db table: ----------------------------------------------------------------- | 1st field | 2nd field | 3rd field | 4th field | 5th field | ----------------------------------------------------------------- | " | " | " | " | " | ----------------------------------------------------------------- | " | " | " | " | " | ----------------------------------------------------------------- | " | " | " | " | " | ----------------------------------------------------------------- | " | " | " | " | " | ----------------------------------------------------------------- Link to comment https://forums.phpfreaks.com/topic/188711-advanced-search-script/ Share on other sites More sharing options...
mmarif4u Posted January 16, 2010 Share Posted January 16, 2010 I can give idea. Create a form with 5 fields and pass the values to PHP variables. And then write a query with OR, AND to meet your needs like: $sql = "select * from table where field1='$f1' OR field2='$f2'"; $f1 and $f2 are variables holding data from a form. Link to comment https://forums.phpfreaks.com/topic/188711-advanced-search-script/#findComment-996200 Share on other sites More sharing options...
greatstar00 Posted January 16, 2010 Share Posted January 16, 2010 depends what u want to search assume all field are text and u just search 1 or 2 words in those fields ignore separate words, if they input 2 words like this two kids will search "there are two kids", and this wont be match, "there are two little kids" and u can jump input search field, like they can have text in field1, and field3, field2 has nothing $arr=array(); if(!empty($field1)) $arr[]='1st_field='."'".$field1."'"; if(!empty($field2)) $arr[]='2nd_field='."'".$field2."'"; if(!empty($field3)) $arr[]='3rd_field='."'".$field3."'"; if(!empty($field4)) $arr[]='4th_field='."'".$field4."'"; if(!empty($field5)) $arr[]='5th_field='."'".$field5."'"; $searchstr=implode(' AND ', $arr); if(!empty($searchstr)) mysql_query("select * from `table` where $searchstr"); Link to comment https://forums.phpfreaks.com/topic/188711-advanced-search-script/#findComment-996202 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.