Forum Moderators: open
For Example:
User1: 330 (total_points)
User1: 310 (total_points)
User1: 280 (total_points)
User2: 330 (total_points)
User2: 310 (total_points)
User2: 280 (total_points)
And so on and so on for all my users. It adds them all together and displays each total_points value for each user_id. I hope I haven't confused you guys to much.
Here is how my table I am querying from is setup.
== Table structure for table race
¦------
¦Field ¦Type ¦Null ¦Default
¦------
¦//**id_race**//¦bigint(15) ¦No ¦
¦race_id ¦bigint(10) ¦No ¦0
¦user_id ¦bigint(15) ¦No ¦0
¦f ¦mediumint(5) ¦No ¦0
¦s ¦mediumint(5) ¦No ¦0
¦race_interval ¦varchar(255) ¦No ¦
¦race_laps ¦smallint(3) ¦No ¦0
¦led ¦varchar(50) ¦No ¦
¦points ¦mediumint(5) ¦No ¦0
¦total_points ¦mediumint(5) ¦No ¦0
¦race_status ¦varchar(50) ¦No ¦
This is my query I am using to get the results I need.
$r_query2=mysql_query("SELECT user_id, points, SUM(points) AS total_points FROM race GROUP BY user_id ORDER BY total_points DESC");
while($get_r_query2=mysql_fetch_array($r_query2))
{
echo "{$get_r_query3['driver']}"; //this query result works fine & is a seperate query all together
"{$get_r_query2['total_points']}";
}
[66.191.161.110...]
Test example below:
[66.191.161.110...]
$r_query3=mysql_query("SELECT user_id, driver FROM user GROUP BY driver");
while($get_r_query3=mysql_fetch_array($r_query3, MYSQL_ASSOC))
{
$r_query2=mysql_query("SELECT user_id, SUM(points) AS total_points FROM race ORDER BY SUM(points) DESC");
while($get_r_query2=mysql_fetch_array($r_query2, MYSQL_ASSOC))
{
echo "<tr>\n<td>" . $get_r_query3['driver'] . "</td>
<td>" . $get_r_query2['total_points'] . "</td>\n
</tr>\n";
}
}
$query = "SELECT user.user_id, user.driver, race.user_id, SUM(race.points) AS total_points "." FROM user, race "." WHERE user.user_id=race.user_id GROUP BY driver ORDER BY total_points DESC";
$result = mysql_query($query) or die(mysql_error());// Print out the contents of each row into a table
while($row = mysql_fetch_array($result)){
echo "<tr>\n<td>" . $row['driver'] . "</td>
<td>" . $row['total_points'] . "</td>
\n</tr>\n";
}