Page 1 of 1

Calculating wins & losses in Football Pool

Posted: Thu Oct 04, 2007 2:39 pm
by elinews
Hi,

I'm creating a site that will take football picks from users and then calculate their records automatically. What would be the best way calculate the records?

Thanks...

Posted: Thu Oct 04, 2007 3:34 pm
by ReverendDexter
What exactly do you mean by calculate their records? Do you mean right picks vs. wrong picks? You'll have to forgive us nerds and our ignorance of sports-like things :)

Posted: Thu Oct 04, 2007 3:38 pm
by elinews
lol. Well I need to get the wins and losses so I'm thinking something like this:

Code: Select all

if ($winner==$chosen_team) {
$wins=$wins+1;
} else {
$losses=$losses+1;
}
And then this would be updated to the database for that user. However I'm having some difficulty with it. Losses always comes out as 15 when it should be 0. Also this process needs to be repeated about 16 times before being output as the final record and if a game is left blank it needs to not effect this.

Posted: Thu Oct 04, 2007 3:51 pm
by s.dot
ReverendDexter wrote:What exactly do you mean by calculate their records? Do you mean right picks vs. wrong picks? You'll have to forgive us nerds and our ignorance of sports-like things :)
I resent that! ;)

For skipping blank ones.. I'd assume the winner is not set if it's blank.. set if its not blank.. so:

Code: Select all

if (isset($winner))
{
    //code here
}
Also, for the losses, echo the values of $winner and $chosen_team to see if they really are ==. My guess is they're not, and the losses part of the if() is always being executed.

Posted: Thu Oct 04, 2007 3:58 pm
by John Cartwright
This sounds like it should be calculated by the database.

How are you storing the users picks as well as the team outcomes?

Posted: Thu Oct 04, 2007 4:14 pm
by elinews
Jcart wrote:This sounds like it should be calculated by the database.

How are you storing the users picks as well as the team outcomes?
Hmm... I think you're right.

I'm using three seperate databases - one for determining the games (what weeks they're on and what season as well as the home, away team and final winner), another for the users info and their records, and a third for picks.

btw thanks scottay your advice seems to have worked.

Posted: Thu Oct 04, 2007 5:20 pm
by elinews
Another thing that needs to be done is for Monday Night Games the users input an overall score. This is used as a tiebreaker - whoever has the closest score wins the tiebreaker. Any suggestions on where to even start with that one?

Posted: Thu Oct 04, 2007 10:10 pm
by John Cartwright
Can you post the table structures?

Posted: Fri Oct 05, 2007 10:15 pm
by elinews
All of them?

Posted: Sat Oct 06, 2007 2:58 am
by John Cartwright
the relevant table(s), yes.

Posted: Mon Oct 08, 2007 1:32 pm
by WorldCom
I had to respond since I just wrote a full football pools script with the tie-breaker score included.

As for the wins/losses, I have one table that contains the totals for the full season. This table is updated at the end of each week with a scipt we fun from our admin area.

For each week, the script just builds the wins/losses on the fly.. heres a small example. This simply checks team 1 greater than team 16 and awards a win.

Code: Select all

if( $user_picks[$i] == 1 ){
		if ( $results_info[($i - 1)] > $results_info[($i + 15)] ){
			$win = $win + 1;
			echo "<FONT COLOR='#004000'><B>";
			} else { $loss = $loss + 1; }
	}
PM me if you would like to have a look at the site.