Welcome to the Geeks & God Static Archive. Read more »

Help with a league table system please?

Joined: 11/28/2008

Hi Guys,

I'm trying to create a league table system for my football content managed system:

So I have my league table:

I want to then create an admin screen which I can enter the results in:

and then when I hit submit the table is updated accordingly.

I have not got the feintest where to start and to create rules such as +3 points for every win, add 2 goals every goal conceded -1 etc. Can anyone point me in the right direction?

Thanks

Chris

Joined: 11/28/2008
Storing the number of wins,

Storing the number of wins, draws and losses, points for and points against, in the database would be enough. Then in the reporting, the Points column would be calculated as:

CODE
$points = ($wins*3) + ($draws * 1);
$goaldifference = $goalsfor - $goalsagainst;

You could even do all that in your MySQL query. What is your table structure?

Paul Davey
Whitford Church
"Everyone who calls on the name of the Lord will be saved." Romans 10:13
"For all have sinned and fall short of the glory of God, and are justified

Joined: 11/28/2008
Thanks - that makes

Thanks - that makes sense:

Here's my table structure:

QUOTE
CREATE TABLE `league_table` (
`team` VARCHAR( 255 ) NOT NULL ,
`played` INT( 2 ) NOT NULL ,
`won` INT( 2 ) NOT NULL ,
`drawn` INT( 2 ) NOT NULL ,
`lost` INT( 2 ) NOT NULL ,
`gf` INT( 3 ) NOT NULL ,
`ga` INT( 3 ) NOT NULL ,
`gd` INT( 3 ) NOT NULL ,
`points` INT( 3 ) NOT NULL
);

How does that work combining the SQL with the php that calls in the data then?

Also when I enter 'Team A' in my textbox, how will php say. Right I want to see all the 'Team A' records in the database and add up their goal difference?

Thanks

Chris

Joined: 11/28/2008
Your MySQL query for the

Your MySQL query for the league table would then be:

CODE
SELECT team,
(won + lost + drawn) AS played,
won, drawn, lost,
gf, ga, (gf - ga) AS gd,
((won*3) + (drawn*1)) AS points
FROM league_table

The "played", "gd" and "points" columns are redundant. I would leave them out - they only add to your work and could lead to inconsistencies if something went wrong.

Plus, you should always add a Primary Key (called ID or similar) to your table - even if you don't think you will need one.

As I see it, you won't be storing the results of each game independently - just the league table?

Your UPDATE query for inserting the data will be simple enough, just need to confirm how you are doing this. You wouldn't even need the league_table table if you stored all the individual games. Just a teams table with the names.

Paul Davey
Whitford Church
"Everyone who calls on the name of the Lord will be saved." Romans 10:13
"For all have sinned and fall short of the glory of God, and are justified

Joined: 11/28/2008
Deleted as I kindof

Deleted as I kindof understand now - please see below thanks

Joined: 11/28/2008
Or maybe something like this,

Or maybe something like this, but I can't get it to save to the database!

CODE
<?php

include("check.php");
include("common.php");

if (isset($_POST['Submit']) && $_POST['Submit'] == 'Submit'){
//Begin processing

//Update the scores for the first team in the first game
$query = "UPDATE league_table SET
             gf = gf + '{$_POST['match1Score1']}',
             ga = ga + '{$_POST['match1Score2']}'
             WHERE team = '{$_POST['match1Team1']}'";

//Update the scores for the second team in the first game
$query = "UPDATE league_table SET
             gf = gf + '{$_POST['match1Score2']}',
             ga = ga + '{$_POST['match1Score1']}'
             WHERE team = '{$_POST['match1Team2']}'";

if($query){
echo 'Football scores and tables have all been entered successfully.';
}
elseif(!$query){
echo 'There was a problem updating the leage table.';
}

} // End processing
?><html>
<head>
<title>Table</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF">
<form name="form1" method="post" action="">
<table width="100%" border="0">
 <tr bgcolor="#FFFF00">
   <td colspan="5">Match One:</td>
 </tr>
 <tr>
   <td>
     <div align="center">Team One</div>
   </td>
   <td>
     <div align="center">Team One Goals Scored</div>
   </td>
   <td rowspan="2" bgcolor="#CCCCCC">&nbsp;</td>
   <td>
     <div align="center">Team Two</div>
   </td>
   <td>
     <div align="center">Team Two Goals Scored</div>
   </td>
 </tr>
 <tr>
   <td>
     <div align="center">
       <input type="text" name="match1Team1">
     </div>
   </td>
   <td>
     <div align="center">
       <input type="text" name="match1Score1">
     </div>
   </td>
   <td>
     <div align="center">
       <input type="text" name="match1Score 2">
     </div>
   </td>
   <td>
     <div align="center">
       <input type="text" name="match1Score 2">
     </div>
   </td>
 </tr>
</table>
 <p>
   <input type="submit" name="Submit" value="Submit" class="button">
   <input type="reset" name="Reset" value="Reset" class="button">
</p>
</form>
</body>
</html>
<?php

}

?>

Joined: 11/28/2008
You need to execute the

You need to execute the UPDATE queries - using the mysql_query() function in PHP.

Paul Davey
Whitford Church
"Everyone who calls on the name of the Lord will be saved." Romans 10:13
"For all have sinned and fall short of the glory of God, and are justified