Hi all
To put you in the picture, I'm trying to create a championship points table for a local kart racing club, by pulling the drivers name and points from an unknown number of tables. The table setup is kinda weird - each table has one race meetings results in (which consists of approx 4 races for each driver). In short, I need to check all the tables, get one instance of each drivers name, then get the points for that driver (of which there will be about 4 entries per table) and add them up to create a total points sum.
Heres what I have so far:
<?
include ("config.php");
$result = mysql_list_tables("$db");
$i = 0 ;
while ($i < mysql_num_rows ($result))
{
$tb_names[$i] = mysql_tablename($result, $i);
$getnames = mysql_query("select name from $tb_names[$i] group by name");
while ($gotnames = mysql_fetch_array($getnames))
{
$total = 0;
$name = $gotnames['name'];
$getpoints = mysql_query("select points from $tb_names[$i] where name = '$name'") or die(mysql_error());
while ($gotpoints = mysql_fetch_array($getpoints))
{
$points = $gotpoints['points'];
$total += $points;
}
echo "$name has $total points<br>";
}
$i++;
}
?>
This gives me all the info I want, but I can't figure out how to put it in order (by points total). I'm guessing I'll need to put it all in a multi-dimesional array and then sort it but I'm not having much luck getting my head round it.
Any help would be greatly appreciated..