Jump to content

Sorting Problem??


Skipjackrick

Recommended Posts

hello again fellas.

 

So, I am trying to make a standings page which will rank every team by the amount of points they have acquired.  I figured out how to sum up the total points but I want to sort the points from Highest to Lowest and keep the (team/points) relationship together.  Could you guys help out a Noobie!?!

 

 

If you have any ideas on how I can populate the Rank column with First, Second, and third etc. that would help out too.  But one step at a time.

 

 

Thanks AGAIN!!!  You guys always help out!!

 

 

$query_sum = "SELECT 
		team_id,
	SUM(points) 
	FROM submit 
	GROUP BY team_id"; 
$result = mysql_query($query_sum) or die(mysql_error());

$kayakwars_header=<<<EOD
<h2><Center>Kayak Wars 2008 Standings</center></h2>
<table width='70%' border='1' cellpadding='2' cellspacing='2' align='center'>
<tr>
	<th>Rank</th>
	<th>Team</th>
	<th>Points</th>
</tr>
EOD;
function get_team_name() {
global $team_id;
global $teamname;

$query_d = "SELECT team_name
	FROM team
	WHERE team_id='$team_id'";
$results_d = mysql_query($query_d) or die(mysql_error());
$row_d = mysql_fetch_array($results_d);
extract ($row_d);
$teamname = $team_name;
}
while($row = mysql_fetch_array($result))
{
$team_id = $row['team_id'];
$points = $row['SUM(points)'];

//get team's name from team table
get_team_name($team_id);

$kayakwars_details .=<<<EOD
<tr>
	<td>First</td>
	<td>$teamname</td>
	<td>$points</td>
</tr>
EOD;
}



$kayakwars_footer ="</table>";

$kayak_wars =<<<KAYAKWARS
	$kayakwars_header
	$kayakwars_footer
KAYAKWARS;

print "There are $num_entries Kayak Wars submissions in our database";
print $kayak_wars;

Link to comment
https://forums.phpfreaks.com/topic/91289-sorting-problem/
Share on other sites

$x=1;
while($row = mysql_fetch_array($result))
{

 

<td>$x</td>

 

EOD;
$x++;
}

 

would produce something like

 

<tr><td>1</td><td>team</td><td>points</td></tr>
<tr><td>2</td><td>team</td><td>points</td></tr>
<tr><td>3</td><td>team</td><td>points</td></tr>

 

etcetera

Link to comment
https://forums.phpfreaks.com/topic/91289-sorting-problem/#findComment-467836
Share on other sites

$x=1;
while($row = mysql_fetch_array($result))
{

 

<td>$x</td>

 

EOD;
$x++;
}

 

would produce something like

 

<tr><td>1</td><td>team</td><td>points</td></tr>
<tr><td>2</td><td>team</td><td>points</td></tr>
<tr><td>3</td><td>team</td><td>points</td></tr>

 

etcetera

 

Cool (one down), but how do I sort the Points from Highest to Lowest?

Link to comment
https://forums.phpfreaks.com/topic/91289-sorting-problem/#findComment-467845
Share on other sites

you have

 

SUM(points) 

 

make it

 

SUM(points) as total_points

 

then after

 

FROM submit

 

add

 

ORDER BY total_points DESC

 

I Tried that and for some reason it doesn't return any data from the database.  I think its trying to GROUP BY team and then we are telling it to ORDER by total_points which contradicts the GROUP BY statement.

 

I am clueless.

Link to comment
https://forums.phpfreaks.com/topic/91289-sorting-problem/#findComment-467854
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.