I have a database of multiple choice questions from people. I would like to see which people are most like the user.
The questions could either be a match, not a match, or the user doesn't care. ie... this is for a roomate software, so a question might be:
Do you want to live with a smoker? (yes) (no) (dc)
I store these values in a database.
To find the reletive "likeness" of roommates, I am trying to cycle through the questions and add up matches as match=1, no match=-1, and dc=0.
This numer would be put into a new array with the user id. ie if user id #6 had a score of twelve then I would have a new entry in the array of 6 | 12. I would then sort this array and echo out the top 8 entries.
Ok... now this is where I am having difficulties... I don't know how to propperly form the For Each look to compare the user answers with a prospective persons answers. Here is my code so far... You can see where I am having problems:
$result=mysql_query("select * from questions where uid==$_SESSION['uid']") or die(mysql_error());
$user=mysql_fetch_array($result)
$result2=mysql_query("select * from questions") or die(mysql_error());
while ($prospect = mysql_fetch_array($result2)) {
$count==0;
BEGIN FOREACH LOOP
if ($prospect == $user) { $count++; } elseif ($prospect != $user) { $count--; }
END FOREACH LOOP
INSERT NUMBER INTO NEW ARRAY ($numbers[])
}
asort($fruits);
$newnumbers = array_slice($input, 0, 8);