Page is a not externally linkable
- Code, Content, and Presentation
-- Databases
---- Table join including link creation & sum


arms - 3:19 pm on Apr 30, 2012 (gmt 0)


You are not returning the link code from your query and maybe (I'm not sure offhand) you need to have an alias for the profit value

Try:

$query = "SELECT SUM(comptipsterselections.profit) as Profit, comptipsterselections.stable, comptipsterboard.link
FROM comptipsterselections INNER JOIN comptipsterboard
ON comptipsterselections.stable=comptipsterboard.stable
WHERE comptipsterboard.comp = 'aintree 2010'
GROUP BY comptipsterselections.stable, comptipsterboard.link
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[Profit];
echo "</td></tr>";
}
echo "</table>";
?>


Thread source:: http://www.webmasterworld.com/databases_sql_mysql/4444822.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com