shcKr- Posted September 4, 2008 Share Posted September 4, 2008 Hey, im just struggling with this: I want to be able to search multiple tables in my mysql database, i have bedroom, dining, living ect. and i want to be able to search them and show the results, i tried: $query = "SELECT dining.title FROM bedroom UNION SELECT bedroom.title FROM dining WHERE bedroom.title LIKE '%".$keywords[$i]."%' OR dining.title = '%".$keywords[$i]."%'"; but that doesn't work, I'm not that experienced in sql and the code I just gave you will probably be laughed at But atleast i tried - but i really do need help on this. Quote Link to comment Share on other sites More sharing options...
fenway Posted September 4, 2008 Share Posted September 4, 2008 That's because after the union the fields "lose" their prefix... why not: ( SELECT title FROM bedroom WHERE title LIKE '%".$keywords[$i]."%' ) UNION ALL ( SELECT title FROM dining WHERE title = '%".$keywords[$i]."%'"; ) Quote Link to comment Share on other sites More sharing options...
shcKr- Posted September 4, 2008 Author Share Posted September 4, 2008 thanks, that did it perfectly You have no idea how long i been trying to get that to work 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.