Hi Will, I've taken the liberty to completely revamp your code (a brain exercise for me) Alls I ask is that you learn from it. Using the below code (although it's untested, so might be a few syntax errors and such), you'll be able to order the stats by any field, and if you add more fields, you won't even have to change any code! It uses the power of PHP, and boy, doesn't it look a lot better? 🙂 Study it, and learn from it if you can.
<?
$connection = mysql_connect("localhost","****","***");
$db = mysql_select_db("restore_stats", $connection);
If (isset($sorting)) { $orderby = "ORDER BY $sorting "; }
If ($sorting == "players") { $orderby .= "ASC"; } else { $orderby .= "DESC"; }
$sql = mysql_query("SELECT * FROM players $orderby ");
// PRINT FIELD NAMES AT TOP OF PAGE WITH LINK TO SORT BY THAT FIELD
$number_of_fields = mysql_num_fields($sql); // STORE NUMBER OF FIELDS
$result = mysql_fetch_array($sql);
echo "<TABLE><TR>";
for ($ii=0; $ii < $number_of_fields; $ii++)
{
$fn = mysql_field_name($result, $ii); // Grabs the field name
$fn = strtoupper(substr($fn,0,1)) . substr($fn,1,strlen($fn)); // Capitalizes first letter
echo "<td bgcolor=gray align=center><A HREF='index.php?sorting=$fn'>$fn</A></TD>"; }
}
echo "</TR>";
// RESET THE RESULT
mysql_data_seek ($sql, 0);
// NOW PRINT ALL INFO FOR EVERY COLUMN FOR ALL RESULTS
while ($result = mysql_fetch_array($sql))
{
echo "<TR>";
for ($i=0; $i < $number_of_fields; $i++)
{
$fv = $result[$i];
echo "<TD align=center><A HREF='index.php?sorting=$fv'>$fv</A></TD>"; }
echo "</TR>";
}
echo "</TABLE>";
?>