monkeytooth Posted April 14, 2010 Share Posted April 14, 2010 Is it possible to query multiple columns at the same time using only one search term.. Lets say I want to make a search box, and just a search box on my site for items i have in my database.. Rather then have the user type a keyword or 2 out in one box and select from a drop down next to it to select a "Type" of search. Where in choosing the "Type" my query would search a specific column. I would rather they just type and hit the search button, and have it search across multiple columns at once. But im not sure if thats possible.. the books I have don't cover it, and im not exactly sure what I should look for in a Search to find the type of query I would need to preform, if it even is possible. In other words.. Table (7 columns)... User types in Keyword, hits search... I want my query to search only 3 of the columns on the 7 column table based on the keyword or words that the user provides. Chances are I will need to use a wildcards as well... if the search yields any results from any or all of the 3 columns then I want to list them out, like I would otherwise with a single column search. Quote Link to comment Share on other sites More sharing options...
monkeytooth Posted April 14, 2010 Author Share Posted April 14, 2010 I'm guessing by the lack of answer its not possible? Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted April 14, 2010 Share Posted April 14, 2010 It's possible. I'm just guessing that people won't help until it looks like you've tried something. Look up "OR" in mysql queries. Quote Link to comment Share on other sites More sharing options...
monkeytooth Posted April 14, 2010 Author Share Posted April 14, 2010 Well trying something I would do, and the "OR" i dont think fits the need per say. But ill give it a quick glance over again to see if I missed something and could be wrong. Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted April 14, 2010 Share Posted April 14, 2010 sure it does roughly like this select field1,field2,etc from mytable where (column1 like '%mysearchvalue' or column1='mysearchvalue') or (column2 like '%mysearchvalue or column2='mysearchvalue') and so and son on Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 14, 2010 Share Posted April 14, 2010 Wrong forum. There is a MySQL forum. This forum is for PHP Help. You can just use LIKE - SELECT * FROM table_name WHERE col1 LIKE '%keyword%' OR col2 LIKE '%keyword%' OR col3 LIKE '%keyword%'; Quote Link to comment Share on other sites More sharing options...
monkeytooth Posted April 14, 2010 Author Share Posted April 14, 2010 Understood that there is a mysql forum or section rather, but this pertains to PHP as well seeing as I am structuring my query through PHP, and am seeking to know if its possible. Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 14, 2010 Share Posted April 14, 2010 Understood that there is a mysql forum or section rather, but this pertains to PHP as well seeing as I am structuring my query through PHP, and am seeking to know if its possible. No, this is a MySQL question. How you create the query is inconsequential to the question of how the query should be formatted. [Moving to appropriate forum]. Besides, the solution has already been provided. 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.