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 Link to comment https://forums.phpfreaks.com/topic/189332-search-forms/ 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%'"; Link to comment https://forums.phpfreaks.com/topic/189332-search-forms/#findComment-999457 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 Link to comment https://forums.phpfreaks.com/topic/189332-search-forms/#findComment-999461 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. Link to comment https://forums.phpfreaks.com/topic/189332-search-forms/#findComment-999541 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.