In my database, I have a table with products and another table that has tags associated with each te product.
When a user views a product page, I want to show the most "related" (or closest) product to the one he is looking at.
So let the product be tagged with 5 different tags. I would like to get prodcuts that have the same 5 tags, and then those that have 4 of the same 5 tags, and then those that have 3 of the same 5 tags, etc.
To do this, I assume that I will need to create one or more MYSQL queries, but I don’t even know where to start.
Compatibility with the same 5 tags is easy, I can just use the WHERE tag = '?' AND tag = '?' ... but how can I get another (4/5, 3/5, 2/5, 1/5)?
Any help would be greatly appreciated!
Cheers Stephen
edits
@Orbits: My tags are on different lines ... if I couldn’t possibly perform a text match, but this is the case. The tag string consists of (id, tag, product_id)
@ cusimar9: Different table, as indicated in the post: P
@vbence: I find it as simple as possible .. that’s it ... but I don’t have a connection table
PRODUCTS:
CREATE TABLE `products` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
...
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
TAGS:
CREATE TABLE `tags` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`type` varchar(70) NOT NULL,
`product_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=116 ;