Calculating wins & losses in Football Pool

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
elinews
Forum Commoner
Posts: 38
Joined: Tue Aug 14, 2007 7:18 pm

Calculating wins & losses in Football Pool

Post 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...
User avatar
ReverendDexter
Forum Contributor
Posts: 193
Joined: Tue May 29, 2007 1:26 pm
Location: Chico, CA

Post 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 :)
elinews
Forum Commoner
Posts: 38
Joined: Tue Aug 14, 2007 7:18 pm

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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?
elinews
Forum Commoner
Posts: 38
Joined: Tue Aug 14, 2007 7:18 pm

Post 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.
elinews
Forum Commoner
Posts: 38
Joined: Tue Aug 14, 2007 7:18 pm

Post 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?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Can you post the table structures?
elinews
Forum Commoner
Posts: 38
Joined: Tue Aug 14, 2007 7:18 pm

Post by elinews »

All of them?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

the relevant table(s), yes.
WorldCom
Forum Commoner
Posts: 45
Joined: Sat Jun 24, 2006 8:14 am
Location: Ontario, Canada

Post 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.
Post Reply