Skip_B
01-13-2010, 12:23 AM
Currently I use the following to find a list of players and arrange them according to their current points totals. I need a cumulative points total.
I need to add the values of the $row['points'], $row['Pts_Q1'], $row['Pts_Q2'], $row['Pts_Q3'], $row['Pts_Q4'] and then display them in order of the largest to smallest.
I could add a field to the table to store the total then order them by that field, something like:
Update Players
Set Total_Points = points+Pts_Q1+Pts_Q2+Pts_Q3Pts_Q4
Then query the table and order it by Total_Points
Or could I just store them to a variable and list them without having to add the field to the table?
From the following code I just need to display the total of all the points values instead of displaying them individually.
echo '<div id="indent_50">';
$counter = 1;
$playerQuery = "SELECT * FROM `players` WHERE `tavern_id` = '{$tavern_id}' ORDER BY `points` DESC";
$player_set = mysql_query($playerQuery) or die(mysql_error());
echo '<table><tbody>';
echo '<tr>
<td class = lbl1>'."Rank" ."</td>
<td class = lbl1>". "Points" ."</td>
<td class = lbl2>". "Name" ."</td>
<td class = lbl2>". "Quarter 1" ."</td>
<td class = lbl2>". "Quarter 2" ."</td>
<td class = lbl2>". "Quarter 3" ."</td>
<td class = lbl2>". "Quarter 4" ."</td>
</tr>";
while ($row = mysql_fetch_array($player_set))
{
echo '<tr>
<td class = data1>'."$counter" ."</td>
<td class = data1>". $row['points'] ."</td>
<td class = data2>". $row['name'] ."</td>
<td class = data2>". $row['Pts_Q1'] ."</td>
<td class = data2>". $row['Pts_Q2'] ."</td>
<td class = data2>". $row['Pts_Q3'] ."</td>
<td class = data2>". $row['Pts_Q4'] ."</td>
</tr>";
$counter++;
}
echo '</tbody></table>';
echo'</div>';
I need to add the values of the $row['points'], $row['Pts_Q1'], $row['Pts_Q2'], $row['Pts_Q3'], $row['Pts_Q4'] and then display them in order of the largest to smallest.
I could add a field to the table to store the total then order them by that field, something like:
Update Players
Set Total_Points = points+Pts_Q1+Pts_Q2+Pts_Q3Pts_Q4
Then query the table and order it by Total_Points
Or could I just store them to a variable and list them without having to add the field to the table?
From the following code I just need to display the total of all the points values instead of displaying them individually.
echo '<div id="indent_50">';
$counter = 1;
$playerQuery = "SELECT * FROM `players` WHERE `tavern_id` = '{$tavern_id}' ORDER BY `points` DESC";
$player_set = mysql_query($playerQuery) or die(mysql_error());
echo '<table><tbody>';
echo '<tr>
<td class = lbl1>'."Rank" ."</td>
<td class = lbl1>". "Points" ."</td>
<td class = lbl2>". "Name" ."</td>
<td class = lbl2>". "Quarter 1" ."</td>
<td class = lbl2>". "Quarter 2" ."</td>
<td class = lbl2>". "Quarter 3" ."</td>
<td class = lbl2>". "Quarter 4" ."</td>
</tr>";
while ($row = mysql_fetch_array($player_set))
{
echo '<tr>
<td class = data1>'."$counter" ."</td>
<td class = data1>". $row['points'] ."</td>
<td class = data2>". $row['name'] ."</td>
<td class = data2>". $row['Pts_Q1'] ."</td>
<td class = data2>". $row['Pts_Q2'] ."</td>
<td class = data2>". $row['Pts_Q3'] ."</td>
<td class = data2>". $row['Pts_Q4'] ."</td>
</tr>";
$counter++;
}
echo '</tbody></table>';
echo'</div>';