RE: [PHP] Search MySQL and Match Whole Words
[snip] I was wondering if anyone knows how to do whole word searches in mysql. I have a search textbox that users can enter in multiple words to search for in the database, but things like the mysql LIKE match any part of a word. Is there a way to search for whole word matches only? Please let me know if you can help. [/snip] the following might not be the most efficient way...and not tested use explode to seperate the words placed in the form field $arrayWords = explode(" ", $_POST['seach_box']) then do query with loop to populate IN statement $getData = "SELECT stuff FROM table "; $getData .= "WHERE column IN ("; for($i = 0; $i < count($arrayWords); $i++){ if($i != (count($arrayWords)-1)){ $getData .= "'" . $arrayWords[$i] . "',"; } else { $getData .= "'" . $arrayWords[$i] . "'"; } } $getData .= ") "; $dbData = mysql_query($getData, your_connection_string); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[Fwd: [PHP] Search MySQL and Match Whole Words]
You mean Full-text searches? Read about them here: http://dev.mysql.com/doc/mysql/en/Fulltext_Search.html Only works with certain table types. Not InnoDB tables (transactional) for instance. Best, Mattias (ps new to this list - messed up on replying first time) Original Message I was wondering if anyone knows how to do whole word searches in mysql. I have a search textbox that users can enter in multiple words to search for in the database, but things like the mysql LIKE match any part of a word. Is there a way to search for whole word matches only? Please let me know if you can help. Thanks, Matt http://sweetphp.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Search MySQL and Match Whole Words
I was wondering if anyone knows how to do whole word searches in mysql. I have a search textbox that users can enter in multiple words to search for in the database, but things like the mysql LIKE match any part of a word. Is there a way to search for whole word matches only? Please let me know if you can help. Thanks, Matt http://sweetphp.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php