Page 1 of 1

[SOLVED] Sorting

Posted: Thu Feb 17, 2005 5:51 am
by professorpool42
Forgive me I am a relative newbie with PHP..

I have constructed a list here:

http://www.jersey.uk8ball.net/rankings.php

I have no problem sorting on any of the columns that feature in the MySQL table, however, I want to sort on the last column that is calculated as follows:

Code: Select all

$totalprizes = $p_proam + $p_open + $p_lsingles + $p_lchamps + $p_oneframe + $p_cabbages + $p_junior + $p_12;
I basically want to sort the table so that the records are displayed in reverse order with the player that has won the most prize money at the top of the list ..

This is the full page code I have constructed so far:

Code: Select all

<?PHP
include("header.php");
include("sidebar.php");

$user="???";
$host="???";
$password="???";
$database="???";

	$connection = mysql_connect($host,$user,$password)
		or die ("Could not connect to the database");
	$db = mysql_select_db($database,$connection)
	    or die ("Could not select the database");

$query = "SELECT * FROM players"; 

$result = mysql_query($query)
	    or die ("Could not execute query");

$rank=1;		

echo "<table cellspacing=3><tr><td><h3>Player Rankings</h3>";
echo "<p>Click on a players name to see further details on each player. Click on an event header to sort by that column</p>";
echo "<table border=1 cellpadding=2><td width=20><b><a href=rankings.php>Rank</a></b></td><td width=200><b><a href=rankings.php?sortt=name>Player</a></td>";
echo "<td width=50><b><a href=rankings.php?sortt=status>Status</a></b></td><td width=50 align=right><b><a href=rankings.php?sortt=proam>Pro Am</a></b></td>";
echo "<td width=50 align=right><b><a href=rankings.php?sortt=open>Open</a></b></td>";
echo "<td width=50 align=right><b><a href=rankings.php?sortt=ls>Ladies Singles</a></b></td>";
echo "<td width=50 align=right><b><a href=rankings.php?sortt=lc>Ladies Champs</a></b></td>";
echo "<td width=50 align=right><b><a href=rankings.php?sortt=one>One Frame</a></b></td>";
echo "<td width=50 align=right><b><a href=rankings.php?sortt=cab>Cabbages</a></b></td>";
echo "<td width=50 align=right><b><a href=rankings.php?sortt=junior>Juniors</a></b></td>";
echo "<td width=50 align=right><b><a href=rankings.php?sortt=125>£125 a man</a></b></td>";
echo "<td width=50 align=right><b>Total</b></td>";

while ($row = mysql_fetch_array($result))

&#123;
   extract($row);
   $totalprizes = $p_proam + $p_open + $p_lsingles + $p_lchamps + $p_oneframe + $p_cabbages + $p_junior + $p_12;
   echo   "<tr><td width=20 align=center>$rank</td>
	        <td width=200><a href=players.php?p_look=".$player_id.">".$player_name."</a></td>\n
			<td width=50>$status</td>\n
			<td width=50 align=right>$p_proam</td>\n
			<td width=50 align=right>$p_open</td>\n
			<td width=50 align=right>$p_lsingles</td>\n
			<td width=50 align=right>$p_lchamps</td>\n
			<td width=50 align=right>$p_oneframe</td>\n
			<td width=50 align=right>$p_cabbages</td>\n
			<td width=50 align=right>$p_junior</td>\n
			<td width=50 align=right>$p_125</td>\n
			<td width=50 align=right>$totalprizes</td>\n";
			$rank = $rank + 1;
&#125;
    echo "</table></td></tr></table>";

include("footer.php");
?>

Pretty please, can anyone put me out of my misery?? :(


feyd | use post formatting tags

Posted: Thu Feb 17, 2005 8:02 am
by qads
You can work out the total prize money in the query it self, something like this:

Code: Select all

SELECT ID,player,(kills+deaths) AS total FROM stat_player ORDER BY total DESC

Posted: Thu Feb 17, 2005 8:11 am
by Maugrim_The_Reaper
x.

Posted: Thu Feb 17, 2005 8:16 am
by professorpool42
That is BRILLIANT, many many thanks!

:D

Posted: Thu Feb 17, 2005 8:35 am
by feyd
please post using the formatting tags we provide such as

Code: Select all

.