THis doesn't make much sense, unless you're keeping to at least one user in each combo.
Do you just want the range (max-min)?
If you want to compare 10 different users, you'll have 45 results:
using combinations without repetition:
n!/r!(n-r)! where n = number of users (10) and r = number chosen (2)
You will see that for a 100 users, you'll have 4950 results (combinations).
As you can see, this gets a bit hefty.
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
OK - Here's a version I got to work - but it's not very pretty and it hasn't been thoroughly tested:
SELECT
products.productname,
users.username,
(SELECT scores.score FROM scores WHERE scores.user_id = $user_id AND scores.product_id = products.product_id) - scores.score AS total_score
FROM
scores
INNER JOIN
products
ON
scores.product_id = products.product_id
INNER JOIN
users
ON
scores.user_id = users.user_id
WHERE
scores.user_id <> $user_id
ORDER BY
scores.product_id
THIS works if your table structure is like this:users
user_id (PK/int)
username (varchar)
products
product_id (PK/int)
productname (varchar)
scores
score_id (int/PK/autoincrement - optional field)
product_id (int)
user_id (int)
score (int)
The "total_score" field is actually the 'difference' between scores.
You can then just have a php loop over the ther resultset.
$pn = ""; $output = "";
while($d = mysql_fetch_array($result)){
if($d['productname'] != $pn){
$output .= "<h3>{$d['productname']}</h3>";
}
$output .= "<p>{$d['productname']}: {$d['total_score']}</p>";
$pn = $d['productname'];
}
//...
echo $output;
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080