On my site I allow the users to select what they like or have interest in. This is done using a pre-defined drop down menu, so every time the user logs into the site they get a list of users that have the same interest as them.
This is done by taking the logged in user’s interests (store in db) and matching with other user on the site, using MySQL WHERE clause. But what I am having trouble is how to show percentage or score next to each users to show how close they match the logged in user interest.
For example:
- user1 — 60% match to your interest
- user1 — 30% match to your interest
- user2 — 20% match to your interest
Each user have 5 different interest, if all match than its 100% match.
A sample of table structure:
CREATE TABLE IF NOT EXISTS `helloworld` (
`id` int(9) NOT NULL AUTO_INCREMENT,
`like1` varchar(300) NOT NULL,
`like2` varchar(300) NOT NULL,
`like3` varchar(300) NOT NULL,
`name` varchar(300) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
example query:
SELECT * FROM helloworld WHERE like1='football' AND like2='art'
I was thinking using COUNT function, but I am unsure? or should I be using sub queries?
EDIT : i am using PHP for server side language. user can NOT type their own likes, must use the pre defined list.
Here’s how I do it. Assume that $like1, $like2 and $like3 are the values from your current user: