Jump to content

Problem with SUM & JOIN


Bradley99

Recommended Posts

Hi,

 

I have some code, which works, but not the way i wan't it too. The code should take win_points from each user in the BETTING table & Add them up, i.e giving the sum. Then the JOIN would display the username linking to the user_id from the betting table.

 

What it's doing now is just displaying me (Admin - User ID #1) with the SUM of ALL win_points of EVERY user in the BETTING table.

 

ANy idea's? Thanks

 

<? 
$standing=mysql_query("SELECT username, SUM(b.win_points) as total_points
FROM users AS u
LEFT JOIN betting AS b 
ON b.user_id = id
ORDER BY total_points");
while($the=mysql_fetch_object($standing)){

echo "  <tr><td class='profilerow'>$the->username</td><td class='profilerow'>$the->total_points</td>
  
   </tr>"; } ?>

Link to comment
https://forums.phpfreaks.com/topic/265370-problem-with-sum-join/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.