Jump to content

How to find related entry in MySQL from an array of key words?


Recommended Posts

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

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

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).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.