Jump to content


This topic is now archived and is closed to further replies.


best way for store and find keyword matches php mysql

Recommended Posts

I'm coding a website link management thing
I'm storing website details: url, title, description, and keywords.

What I want to be able to do is identify releated websites. it doesn't have to be perfect
I present them to the visitors as "possibley related websites"

My initial idea was put the keywords in seperate fields and to do multiple searches one keyword at a time.
but I'm thinking perhaps I should create a full-text index and do something better.
perhaps seach the title and the description also

suppose I had a string of keywords "fish,fishing,fish scales,fish tail, shark,fishing rod"

You guys are usually really good at comming up with ideas, I thought I'd ask for your ideas before I build the tables



Share this post

Link to post
Share on other sites
I normally do these open searches.  Like I have a form

[code]<form name="searchform" id="searchform" action="whatever.php" method="get or post">
<label for="searchtext">Search</label>
<input name="searchtext" id="searchtext" type="text" maxlength="120" />
<br />
<input name="searchsubmit" id="searchsubmit" type="submit" value="Search It!" />

THen you can process it, and when you do, run a special query, with the query have it check everyfield of everydatabase.  With 2 percentages, this makes it guarantee any close match, for any field.
Like this

$search = mysql_real_escape_string($_GET['searchtext']);
$search = strtolower($search);
$select = "SELECT * FROM tablename WHERE url LIKE '%$search' OR title LIKE '%$search' OR description LIKE '%$search' OR keywords LIKE '%$search';";
$query = mysql_query($select);
if ($row = mysql_fetch_array($query)) {
// do whatever

Share this post

Link to post
Share on other sites


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.