Jump to content


This topic is now archived and is closed to further replies.


Standings help

Recommended Posts

Relatively new to php / mysql and need some help with generating standings from a football schedule. I have a 'schedules' table in a mysql database with 'vteam', 'vscore', 'hteam', 'hscore' among the columns.

I have it so users login and input scores which get posted to my website but would also like this process to update standings as well.

I've pieced together some code to generate the standings page. I've managed to generate each team's away W-L records so far but the problem is trying to do the same for home records and keeping the info on the same line of the html table as the relevant team. I've been playing with the UNION idea for some time now and can't get it working right. Any help would be awesome. Thanks in advance.

Below is the relevant code which is working for the away records:

echo "<table align=center width=530 cellpadding=1 cellspacing=0 border=0>";
echo "<tr><td colspan=9><b>2005 Standings</b></td></tr>";
echo "<tr><td>Team</td><td>GP</td><td>W</td><td>L</td><td>Home</td><td>Road</td><td>F</td><td>A</td><td>Pts</td></tr>";

$sqlquery = '(SELECT vteam AS team,SUM(IF(vscore > hscore, 1, 0)) AS vwins,
SUM(IF(hscore > vscore, 1, 0)) AS vlosses FROM schedules GROUP BY team)';

$result = mysql_query($sqlquery);
while($row = mysql_fetch_array($result)) {

echo "<tr><td>$row[team]</td><td></td><td></td><td></td><td></td><td>$row[vwins]-$row[vlosses]</td><td></td><td></td><td></td></td>";

echo "</table>";


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.