ivytony Posted March 9, 2009 Share Posted March 9, 2009 I'd like to find related entries in MySQL database by looking for similar terms as the current article title. For example, the current article title is 'Giant Scale RC Hawker Sea Fury (HD)' and after using explode for the title, the key words will become 'Giant', 'Scale', 'RC', 'Hawker', 'Sea', 'Fury', and 'HD'. I want to find related entries in database that have one or more of the key words. I wonder how to do it effective? Thanks Link to comment https://forums.phpfreaks.com/topic/148546-how-to-find-related-entry-in-mysql-from-an-array-of-key-words/ Share on other sites More sharing options...
fenway Posted March 9, 2009 Share Posted March 9, 2009 LIKE will work, albeit poorly. Link to comment https://forums.phpfreaks.com/topic/148546-how-to-find-related-entry-in-mysql-from-an-array-of-key-words/#findComment-780148 Share on other sites More sharing options...
kickstart Posted March 9, 2009 Share Posted March 9, 2009 Hi Explode the string containing 'Giant Scale RC Hawker Sea Fury (HD)'. Then loop though the resulting array doing a like clause for each item. <?php $wordArray = explode(" ",'Giant Scale RC Hawker Sea Fury (HD)',20); $WhereClause = ""; foreach($wordArray as $value) { $WhereClause = (($WhereClause) ? " AND " : " WHERE ")." LIKE '%$value%' "; } $sql = "SELECT modelid from models $WhereClause ORDER BY modeldate"; ?> All the best Keith Link to comment https://forums.phpfreaks.com/topic/148546-how-to-find-related-entry-in-mysql-from-an-array-of-key-words/#findComment-780196 Share on other sites More sharing options...
aschk Posted March 10, 2009 Share Posted March 10, 2009 You may wish to consider FULLTEXT search options. Splitting the string into it's component parts and using the MATCH clause with them. See the following reference: http://dev.mysql.com/doc/refman/5.1/en/fulltext-search.html The one requirement is that the tables are MyISAM (until falcon sorts itself out). Link to comment https://forums.phpfreaks.com/topic/148546-how-to-find-related-entry-in-mysql-from-an-array-of-key-words/#findComment-780998 Share on other sites More sharing options...
fenway Posted March 13, 2009 Share Posted March 13, 2009 Don't hold your breath on Falcon... I'd check out Sphinx. Link to comment https://forums.phpfreaks.com/topic/148546-how-to-find-related-entry-in-mysql-from-an-array-of-key-words/#findComment-783836 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.