isaac_cm Posted December 9, 2006 Share Posted December 9, 2006 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#msg481732thanks Quote Link to comment Share on other sites More sharing options...
artacus Posted December 9, 2006 Share Posted December 9, 2006 So if your current id is 42, you'll want to pull 39,40,41 right?[code]SELECT *FROM products WHERE id < 42ORDER BY id DESC LIMIT 3[/code] Quote Link to comment Share on other sites More sharing options...
isaac_cm Posted December 9, 2006 Author Share Posted December 9, 2006 No,I want the [b]Higher[/b] 3 products that matches common keywords between them I want the most 3 product similar to the current one to suggest to the customer to buy them in addition to the current selected one (like amazon.com)thanks Quote Link to comment Share on other sites More sharing options...
Eric_Ryk Posted December 9, 2006 Share Posted December 9, 2006 How are the keywords stored in your database? Are they just in a field separated by commas or spaces? Quote Link to comment Share on other sites More sharing options...
artacus Posted December 10, 2006 Share Posted December 10, 2006 Oh so to get 43,44,45 [code]SELECT *FROM products WHERE id > 42ORDER BY id LIMIT 3[/code] Quote Link to comment Share on other sites More sharing options...
isaac_cm Posted December 10, 2006 Author Share Posted December 10, 2006 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#msg481732Eric_Ryk: the keywords is stored in one field its type is "MEDIUMTEXT" and "," is the separator characterwaiting for replythanks Quote Link to comment Share on other sites More sharing options...
isaac_cm Posted December 11, 2006 Author Share Posted December 11, 2006 I will explain what I need in steps:1- get the current selected products keywords and store it in a variable or array2- 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 coursethanks Quote Link to comment Share on other sites More sharing options...
fenway Posted December 15, 2006 Share Posted December 15, 2006 Higher than what? And how do you intend to pase this keyword field? Quote Link to comment Share on other sites More sharing options...
isaac_cm Posted December 16, 2006 Author Share Posted December 16, 2006 ok, nevermind all I need is a good 'product recommendation' system it is the first time I do this so any any idea will be appreciatedthanks Quote Link to comment Share on other sites More sharing options...
fenway Posted December 16, 2006 Share Posted December 16, 2006 I'm still not sure I understand how you want this to work, or what's in the keywords field, and what the numbers mean. Quote Link to comment Share on other sites More sharing options...
artacus Posted December 17, 2006 Share Posted December 17, 2006 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 pJOIN categories AS cat ON FIND_IN_SET(c.id,p.keywords)WHERE p.id = 42ORDER BY cat.id DESC LIMIT 3[/code] Quote Link to comment Share on other sites More sharing options...
isaac_cm Posted December 17, 2006 Author Share Posted December 17, 2006 First thank you very much guys for your interest to help me and learning somthing newI really wish if it so simple , I was adviced to used keywords to get recommend products related to the current selected oneit 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 greatexample 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 Quote Link to comment Share on other sites More sharing options...
fenway Posted December 18, 2006 Share Posted December 18, 2006 The next step would be to break out the comma-separated list into a proper table. Quote Link to comment Share on other sites More sharing options...
artacus Posted December 18, 2006 Share Posted December 18, 2006 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. Quote Link to comment Share on other sites More sharing options...
isaac_cm Posted December 18, 2006 Author Share Posted December 18, 2006 ok, if I made a child table contains keywords for a product in the "products" table , then it is only simple join or I have to do something elsethanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.