langemarkdesign Posted April 21, 2010 Share Posted April 21, 2010 I am working on a PHP search engine. What I am doing is running a MySQL Like Query for multiple keywords, and would like to sort the results according to the number of the keywords it contains. Here is my current code: $query = "SELECT * FROM library WHERE title LIKE '%$keyword1%' OR title LIKE '%$keyword2%' OR title LIKE '%$keyword3%'"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { echo $row['title'] . "<br>"; } And an example of what I want: $keywords = array("homemade", "lasagna", "ingredients"); With those keywords I would get these results: home made lasagna worlds best lasagna homemade ingredients easy at home lasagna fresh lasagna ingredients how to make homemade lasagna with just 6 ingredients And here's how I want it sorted: how to make homemade lasagna with just 6 ingredients fresh lasagna ingredients homemade ingredients easy at home lasagna home made lasagna worlds best lasagna Sorting results with identical number of keywords alphabetically. Any help would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/199320-php-mysql-like-query-sort-by-best-match/ Share on other sites More sharing options...
AdRock Posted April 21, 2010 Share Posted April 21, 2010 Why don't you use mysql full text searches? It just searches the query using those keywords entered Link to comment https://forums.phpfreaks.com/topic/199320-php-mysql-like-query-sort-by-best-match/#findComment-1046110 Share on other sites More sharing options...
langemarkdesign Posted April 21, 2010 Author Share Posted April 21, 2010 Why don't you use mysql full text searches? It just searches the query using those keywords entered How would I do that? Are there any examples or documentation? Link to comment https://forums.phpfreaks.com/topic/199320-php-mysql-like-query-sort-by-best-match/#findComment-1046117 Share on other sites More sharing options...
AdRock Posted April 21, 2010 Share Posted April 21, 2010 http://www.devarticles.com/c/a/MySQL/Getting-Started-With-MySQLs-Full-Text-Search-Capabilities/ Link to comment https://forums.phpfreaks.com/topic/199320-php-mysql-like-query-sort-by-best-match/#findComment-1046129 Share on other sites More sharing options...
langemarkdesign Posted April 21, 2010 Author Share Posted April 21, 2010 http://www.devarticles.com/c/a/MySQL/Getting-Started-With-MySQLs-Full-Text-Search-Capabilities/ Figured it out, thanks for your help Link to comment https://forums.phpfreaks.com/topic/199320-php-mysql-like-query-sort-by-best-match/#findComment-1046131 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.