Jump to content

finding the higher 3 products from keywords


isaac_cm

Recommended Posts

Hello,
I need to make sql that fetch me 3 results of the higher 3 products related to the current product

the search will be based on keywords exists in every product (ex "keys")

this topic is a continue to my previous question
http://www.phpfreaks.com/forums/index.php/topic,116249.msg481732.html#msg481732

thanks
Link to comment
Share on other sites

artacus: you got me wrong, but I wish the problem was that easy, please look at my previous topic
http://www.phpfreaks.com/forums/index.php/topic,116249.msg481732.html#msg481732

Eric_Ryk: the keywords is stored in one field its type is "MEDIUMTEXT" and "," is the separator character

waiting for reply
thanks

Link to comment
Share on other sites

I will explain what I need in steps:

1- get the current selected products keywords and store it in a variable or array

2- loop through all the keywords, in each loop I have to get the number of finding this word in all products of the current category (ex: bags)

(ex: keywords = "satin bag(5), classy(9), magnetic clasp(2), Dark(7), Navy(4), Fabric(15)"

3- compare all number and get the higher 3 results (Fabric(15), classy(9), Dark(7)) then get one product id from each of the 3 results to display as a recommended product and exclude the current one of course

thanks
Link to comment
Share on other sites

Ok, I think I'm starting to get you now.
You could make your life much easier if you only stored the id's of the related categories in your field. Once again I'm going to make an assumption that the 15 in Fabric(15) is the category id for Fabric? Yes?

If so, I'd change your keywords to only store the ids like so "2,4,5,7,9,15"

Then you can join your categories like so:
[code]
SELECT cat.*
FROM products AS p
JOIN categories AS cat ON FIND_IN_SET(c.id,p.keywords)
WHERE p.id = 42
ORDER BY cat.id DESC LIMIT 3[/code]
Link to comment
Share on other sites

First thank you very much guys for your interest to help me and learning somthing new

I really wish if it so simple , I was adviced to used keywords to get recommend products related to the current selected one

it is based on keywords stored in every product, and by doing select statement I should get the most higher 3 related products to the current one like this

(keyword, num of occurrence), but this solution has a problem that I do not have the prod_id field in the result so I will never know which product to get

(note: In my databse design I can get all product info by the key field prod_id)

however if you have any other "simple" solution or 3rd party script for this it will be great

example site for what I mean:
http://www.qvcuk.com/ukqic/qvcapp.aspx/main.detail.tpl.uktsv.item.tsv/left.html.file.tsvmetadrill,html

(notice the recommended 2 product on the right)

many thanks my friends
Link to comment
Share on other sites

The MySQL manual can tell you more about FIND_IN_SET(). But real quickly, it will let you use a comma seperated field in the same way you use something like WHERE category.id IN(2,3,15,32). BTW, you can't use IN (csvField) because it only matches the first value.
Link to comment
Share on other sites

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.