I am looking at something like this
$query = "SELECT catid, userid FROM prod_list WHERE userid = logged-in-user" //user's chosen categories
$rs_match = mysql_query($query);
while($data = mysql_fetch_array($rs_match)开发者_如何学Go)
{
$match_pattern = $data['catid'];
echo $match_pattern; //debugging purposes
Wears id-(1)
shoes id-(3)
books id-(4)
//Please How can I get and list other users who have the same choices with the logged in user?
//Thank you
//Exact same choices or rated choices based on match
//Priority should be given to exact results
//100% match results should be displayed on top others follow
}
Something like that
SELECT userid, COUNT(catid) as matches FROM prod_list WHERE catid IN (CATID_ARRAY_HERE) GROUP BY userid ORDER BY matches DESC
You can do it using nested query:
SELECT DISTINCT userid FROM prod_list WHERE catid NOT IN (
SELECT catid FROM prod_list WHERE catid NOT IN (
SELECT catid FROM prod_list WHERE userid = logged-in-user
)
)
The last query select all categories of logged-in-user, the second one all the categories not in logged-in-user preferences and the firs (external) one all the user wich do not have categories that logged-in-user not have.
E.g if logged-user has (motor, computer, sports) in his categories list
UserA has (motor, computer)
UserB has (motor, computer, bike)
UserA will be selectes while UserB wont
SELECT * FROM users
WHERE is_login = 1
AND
user_id IN (SELECT user_id FROM prod_list WHERE cat_id = {$id})
精彩评论