mtroute 0 Newbie Poster

I m trying to create a table using the results of a SUM on separate tables within a single DB. I have tried various join scripts but can't seem to get it right. As a work around, I have created a single SUM table for each Table and run the script multiple times. Here is what I have: http://www.troute.com/madness I am trying to show itn the first table total scores for each player sorted in descending order.

I would appreciate some tips on how to use JOIN properly.

Here is the existing code:

<?php 
     
$db_host = 'my_host'; 
$db_user = 'username'; 
$db_pwd = 'pass'; 

$database = 'my_db'; 
$table = 'Dirk'; 


if (!mysql_connect($db_host, $db_user, $db_pwd)) 
    die("Can't connect to database"); 

if (!mysql_select_db($database)) 
    die("Can't select database"); 

// sending query 
$result = mysql_query("SELECT sum( Total ) FROM  {$table}"); 
if (!$result) { 
    die("Query to show fields from table failed"); 
} 

$fields_num = mysql_num_fields($result); 

echo "<table width='150'><tr>"; 
// printing table headers 

// printing table rows 
while($row = mysql_fetch_row($result)) 
{ 
    echo "<tr>"; 

    // $row is array... foreach( .. ) puts every element 
    // of $row to $cell variable 
    foreach($row as $cell) 
    echo "<td style=border-collapse:collapse ='1' bgcolor=#FFFFFF><font face=arial size='3'/>$table</td>"; 
        echo "<td style=border-collapse:collapse ='1' bgcolor=#FFFFFF width='35' align='right'><font face=arial size='3'/>$cell</td>"; 

    echo "</tr>\n"; 
} 
mysql_free_result($result); 
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.