influenceuk Posted July 23, 2007 Share Posted July 23, 2007 Hi guys, Really having some issues getting a search feature implemented onto my site. Basically i am after a search which will search the database (2 tables) and display the results the user has searched for. I have tried the codes from the library from PHP Freaks, yet had no luck. Can any one help me please? Quote Link to comment Share on other sites More sharing options...
Fadion Posted July 24, 2007 Share Posted July 24, 2007 Maybe some code you wrote should help track the problem. Normaly, for a basic search you should write something like: $query = "SELECT * FROM table WHERE field LIKE '%$search%'"; $results = @mysql_query($query) or die(); while($values = mysql_fetch_array($results)){ echo $values['column']; } where $search is the value retrieved from the input. For searching your two tables you have a set of different possibilites. U can use 2 different queries: $queryTable1 = "SELECT * FROM table1 WHERE column LIKE '%$search%'"; $queryTable2 = "SELECT * FROM table2 WHERE column LIKE '%$search%'"; Then you execute the query and get the data for each table. If the tables columns are identical then u can use UNION between the two queries: $query = "SELECT * FROM table1 WHERE column LIKE '%$search%' UNION SELECT * FROM table2 WHERE column LIKE '%$search%'" If the case is different than i guess you must use the appropriate JOIN command but im not familiar with those so i cant say much. Hope i helped. Quote Link to comment 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.