Solarpitch Posted August 6, 2008 Share Posted August 6, 2008 Hey, I am currently using the below basic sql to search a table in MySql database. It works fin when there is one keyword for example "pine" but if two keywords are entered it returns noting ... eg "pine oak". What would I need to do to get it to work if 2 or more works were entered? <?php $sql = "SELECT * FROM products where product_name LIKE '%$keyword%' "; ?> Link to comment https://forums.phpfreaks.com/topic/118520-searching-database-with-2-or-more-keywords/ Share on other sites More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 Check out FULLTEXT indexes. Link to comment https://forums.phpfreaks.com/topic/118520-searching-database-with-2-or-more-keywords/#findComment-610165 Share on other sites More sharing options...
lemmin Posted August 6, 2008 Share Posted August 6, 2008 Check both criteria: <?php $sql = "SELECT * FROM products where product_name LIKE '%$keyword%' AND product_name LIKE '%$keyword2%'"; ?> Link to comment https://forums.phpfreaks.com/topic/118520-searching-database-with-2-or-more-keywords/#findComment-610166 Share on other sites More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 1) You'd probably use OR. 2) That gets a little inefficient after a while. Link to comment https://forums.phpfreaks.com/topic/118520-searching-database-with-2-or-more-keywords/#findComment-610169 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.