php - Advice me on the algorithm to match people -


currently working on project need match people based on categories of food like:

this scenario:

i have list of users , favorite foods in database. database structure follows:

users(id,name,email,gender,dob) fav_food (id,user_name,food,desc) 

data users table:

1, alice, alice@lala.com, female, 11 oct 2010

2, bob, bob@lala.com, male, 12 oct 2010

3, jason, jason@lala.com, male, 13 oct 2010

data fav_foods table:

1, alice, apple, desc

2, alice, banana, desc

3, alice, pear, desc

4, bob, apple, desc

5, bob, custard cake, desc

6, jason, banana,some desc

6,jason,apple,some desc

imagine alice apple,banana & pear. how able match people based on favorite food? example, first check if likes apple,banana , pear (inclusive of three) , go permutation of 2 combination (apple,banana)(apple,pear)(banana,pear)(banana,apple) ....and on.....

imagine venn diagram interaction interested. interested suggest users matched. there algorithm available can use php?

what join fav_foods table , count matches:

select u2.user_name,count(*) likeness  `fav_food` u1 inner join `fav_food` u2 on (u1.user_name = 'alice' ,                                                   u1.food = u2.food ,                                                   u2.user_name != "alice") group u2.user_name  order likeness desc 

it output:

user_name   likeness jason       2 bob         1 

the trick on conditions of inner join... =)

hope helps

edited: oops corrected query =)


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -