Performing MySQL search based on multiple keywords
Posted: Tue May 12, 2009 11:17 am
Hello
This query sounds so straightforward, but I'll be damned if I can crack it.
I have a Product page that has a field named "tags". In tags could be something like this:
Other products may also have
So: BIG ROBOT has "robot, fun, toy" in it's tags, and a FUNKY CAN OPENER has "fun, toy" in it's tag. I want "FUNKY CAN OPENER" to be displayed at the bottom of the BIG ROBOT's product page.
does this makes sense?
Iv'e tried the following, but it fails.
This query sounds so straightforward, but I'll be damned if I can crack it.
I have a Product page that has a field named "tags". In tags could be something like this:
Code: Select all
robot, fun, toyWhat I need is for one product to be rendered, and if it sees in the rest of the database "robot" or "fun" or anything else that is in it's own tags field, then I want it to render the data from that result.robot, fun
So: BIG ROBOT has "robot, fun, toy" in it's tags, and a FUNKY CAN OPENER has "fun, toy" in it's tag. I want "FUNKY CAN OPENER" to be displayed at the bottom of the BIG ROBOT's product page.
does this makes sense?
Iv'e tried the following, but it fails.
Code: Select all
$result = mysql_query ("SELECT * FROM 6_products WHERE id = '$myprod'");
while ($row = mysql_fetch_object($result))
{
echo "
<table width='100%' cellspacing='0' cellpadding='0'>
<tr><td>
<div class='productdescription'>$row->description</div>
<div class='productimage'><img src='images/productphotos/$row->photo'></div>
<div class='productbuynow'>TAKE A CLOSER LOOK | <font color='#ff0000'>ONLY £6.00 BUY NOW</font></div>
<div class='productfreeshipping'><img src='images/icon_freeshipping.png' /></div></td></tr>
<tr><td>
<div class='youtube'>$row->video</div>
</td></tr></table>
";
$resulttags = mysql_query ("SELECT * FROM 6_products WHERE tags LIKE '%$row->tags%'");
while ($rowtags = mysql_fetch_object($resulttags))
{
echo "$rowtags->title";
}
}