views:

40

answers:

2

Hi, i'm writing a kind of 'dating service' website (just for fun & practice).

But right now i'm stuck. I use PHP and MySQL.

Every new member must complete 'What do you like (to do)?' question separated by commas:

Like this:

computing, dancing, reading, TV, movies

and so on.

My question is 'how can i show recommended people to someone'?

i.e.

MEMBER A:

computing, dancing, reading, TV, movies

MEMBER B:

books, cellphones, rugby

MEMBER C:

dancing, movies

In this scenario, A & C have more chances to get along than A & B or B & C

I'll appreciate any hint to try to do this real, or your own ideas to solve this. Thanks!

PS: Sorry about my english

+1  A: 

Well, you could start by counting how many interests each member have in common, and then you just select the one that has the most in common. I am pretty sure that you could do this with just a SQl Query, or maybe 2... Well, of course, depending on your database structure.

You would need to post the database structure you are using, so me and others and actually give you some code...

Uoli
My DB's structure is pretty simple, one row per member with his/her data:id, name, last name, country, mail, password, interests.In interest is where i save those separted with commas.
HarzIce
I would recommend splitting the interests from csv in one field into a separate table. That will make it orders of magnitude easier (and faster) to find matches than trying to do substring matching and counting in sql.
Tesserex
Yeah, i completely agree with @Tesserex, do not store the interests as a String Field. I would create a simple table for interests, and then create a relationship, many-to-many, beetween member and interest. This way its easier to find out how many interests 2 members have in common.
Uoli
+1  A: 

I would say that step one is to split their list of interests into separate words. Then make a table with only two columns: user and interest.

    | user | interest  |
    |------|-----------|
    |  A   | computing |
    |  A   |  dancing  |
    | ...  |  .......  |
    |  C   |   movies  |

and so on. Then all you need to do is join the table with itself and count the number of interests in common with the target user. Group by user, and sort by the count of interests in common (assuming that's your metric for how well they will get along). I can't think of the sql for this right off the top of my head, but maybe it's a good exercise for you. Or maybe someone else will post it as an answer. Good luck!

Tesserex
Thanks for your idea, i like it. Will it have a lot of SQL processing?
HarzIce
Far less than having a string field for interests, I can say that much. How long the query actually takes depends heavily on how many users you have and their number of interests.
Tesserex