Table join including link creation & sum

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Petrushka
    New Member
    • Apr 2012
    • 1

    Table join including link creation & sum

    Good evening

    I'm attempting to produce a single table of bets placed by players on my website. I currently have the information across two tables, as per the screenshots below:

    comptipsterboar d:


    comptipstersele ctions:


    Ideally, I'd like to pull the player name from comptipstersele ctions, and sum the selection profits for each player using group by. However, I'd like the final table to provide a link to each players selections, for which I will need the info from comptipsterboar d.

    My initial attempt can be found here: http://www.further-flight.co.uk/site...r/sp/2010a.php - it appears to be pulling the correct info from the comptipsterboar d table, but the links aren't functioning and the profit isn't showing up correctly.

    For info, here is the top scoring player's selections: http://www.further-flight.co.uk/site...2010/super.php

    Code:
    					$query = "SELECT SUM(comptipsterselections.profit), comptipsterselections.stable
    							  FROM comptipsterselections INNER JOIN comptipsterboard  
    							  ON comptipsterselections.stable=comptipsterboard.stable
    							  WHERE comptipsterboard.comp = 'aintree 2010' 
    							  GROUP BY comptipsterselections.stable ORDER BY SUM(comptipsterselections.profit) DESC";
    			  
    						 
    					$result = mysql_query($query) or die(mysql_error());
    
    				//	Set-up table
    				
    					echo "<table class='correctenglish' border='1' cellpadding='4' cellspacing='0' width='75%'>";
    					echo "<tr class='toprow'> 	<th>Stable</th> <th>Daily Profit</th></tr>";
    				
    				
    				// Print out result
    					while($row = mysql_fetch_array($result)){
    					
    					$link='/site/competitions/tipster'.$row['link'];
    					
    					echo 	"<tr><td>"; 
    					echo 	"<a href='$link'>";
    					echo 	$row['stable'];
    					echo 	"</td><td>"; 
    					echo 	" £". $row['SUM(comptipsterselections.profit)'];
    					echo 	"</td></tr>"; 
    					}
    					echo 	"</table>";
    				?>
    Any assistance would be greatly appreciated.
Working...