cs1h Posted January 21, 2010 Share Posted January 21, 2010 Hi , I having been trying to create a keyword search form using php and mysql but have had little luck doing what I need to do. I want the user to be able to put multiple words into a single search box and then search three columns in a table to find possible matches. Can anyone help me with this or point me towards a good tutorial? Thanks, Cs1h Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted January 21, 2010 Share Posted January 21, 2010 It really just comes down to building the query. If you mean that they will enter one set of keywords that will be searched against all three columns separately, it could be as easy as $kw = $_POST['keywords']; $query = "SELECT * FROM table WHERE column1 LIKE '$kw%' OR column2 LIKE '$kw%' OR column3 LIKE '$kw%'"; Quote Link to comment Share on other sites More sharing options...
cs1h Posted January 21, 2010 Author Share Posted January 21, 2010 Hi, Thanks for the reply. If there was multiple words put forward by the user would I have to split the words some how and then search them individually or will sql do this for me? Thanks, Cs1h Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted January 21, 2010 Share Posted January 21, 2010 If you want to search each word by itself, yes you would need to split them up (maybe explode them on the space) then just build out the query to search each field for each word. 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.