The Little Guy Posted July 10, 2007 Share Posted July 10, 2007 Anyone know how to do a keyword search? Right now, I have this: $q = $_POST['q']; $strings = explode(" ",$q); $str = preg_replace("/ /","%",$q); $str = preg_replace("/%%/","%",$str); if $q looked like this: The dog jumped the fence it would convert it to this: The%dog%jumped%the%fence $query = "SELECT * FROM news_news WHERE title LIKE '%$str%' OR content LIKE '%$str%' OR date LIKE '%$str%'"; That does an OK job, but How could I get it to do a keyword search where it treats every word as a keyword, and not as a string? Link to comment https://forums.phpfreaks.com/topic/59198-mysql-keyword-search/ Share on other sites More sharing options...
trq Posted July 10, 2007 Share Posted July 10, 2007 A full text search may be of benifit. Its all in the MySql manual. Link to comment https://forums.phpfreaks.com/topic/59198-mysql-keyword-search/#findComment-294088 Share on other sites More sharing options...
jitesh Posted July 10, 2007 Share Posted July 10, 2007 mysql> SELECT * FROM articles WHERE MATCH (title,body) -> AGAINST ('+MySQL -YourSQL' IN BOOLEAN MODE); +----+-----------------------+-------------------------------------+ | id | title | body | +----+-----------------------+-------------------------------------+ | 1 | MySQL Tutorial | DBMS stands for DataBase ... | | 2 | How To Use MySQL Well | After you went through a ... | | 3 | Optimizing MySQL | In this tutorial we will show ... | | 4 | 1001 MySQL Tricks | 1. Never run mysqld as root. 2. ... | | 6 | MySQL Security | When configured properly, MySQL ... | +----+-----------------------+-------------------------------------+ Link to comment https://forums.phpfreaks.com/topic/59198-mysql-keyword-search/#findComment-294098 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.