By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,615 Members | 1,961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,615 IT Pros & Developers. It's quick & easy.

Table join including link creation & sum

P: 1
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:



Ideally, I'd like to pull the player name from comptipsterselections, 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 comptipsterboard.

My initial attempt can be found here: - it appears to be pulling the correct info from the comptipsterboard 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:

Expand|Select|Wrap|Line Numbers
  1.                     $query = "SELECT SUM(comptipsterselections.profit), comptipsterselections.stable
  2.                               FROM comptipsterselections INNER JOIN comptipsterboard  
  3.                               ON comptipsterselections.stable=comptipsterboard.stable
  4.                               WHERE comptipsterboard.comp = 'aintree 2010' 
  5.                               GROUP BY comptipsterselections.stable ORDER BY SUM(comptipsterselections.profit) DESC";
  8.                     $result = mysql_query($query) or die(mysql_error());
  10.                 //    Set-up table
  12.                     echo "<table class='correctenglish' border='1' cellpadding='4' cellspacing='0' width='75%'>";
  13.                     echo "<tr class='toprow'>     <th>Stable</th> <th>Daily Profit</th></tr>";
  16.                 // Print out result
  17.                     while($row = mysql_fetch_array($result)){
  19.                     $link='/site/competitions/tipster'.$row['link'];
  21.                     echo     "<tr><td>"; 
  22.                     echo     "<a href='$link'>";
  23.                     echo     $row['stable'];
  24.                     echo     "</td><td>"; 
  25.                     echo     " ". $row['SUM(comptipsterselections.profit)'];
  26.                     echo     "</td></tr>"; 
  27.                     }
  28.                     echo     "</table>";
  29.                 ?>
Any assistance would be greatly appreciated.
Apr 21 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.