Making this NFL-bet code work :-)
Posted: Wed Aug 30, 2006 9:27 am
feyd | Please use
How do I make it work with multile winners?
- Thanx
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hey Everyone
I am making a site, where people can bet on NFL results. On each game you bet on a winner and how much the winning team is gonna beat the loosing team.
That all works fine, but I have the following code, that I use, when no one has guessed the correct points that differentiates the winning team from the loosing team. This code works fine, but only stores 1 winner (the one that gets closest to the actual number). But I also want it to work, when two or more people is equally closest to the number. How do I store when there's more that 1 "winner"?Code: Select all
// Just a big number that gets overrided by the users guesses
$smallestdist = 9999;
// Stores the winner
$winner = null;
// Select bets from DB that equals the specific game number
$sql = "select * from nflbets where kampnr = '$kampnr'";
$result = mysql_query($sql3) or die(mysql_error());
// Loop through the bets
while ($row = mysql_fetch_array($result))
{
// Checks if user has the correct winner
if($row["vinder"] == $vinder)
{
// Calculates the difference between the correct number and the users guess
// I'm using abs, so it also works if you guess is below the actual number.
$userdist = abs($maalforskel - $row["maalforskel"])
// if the users guess is smaller than the number stored in smallesdist
if($userdist < $smallestdist)
{
// Put the number in smallest Dist
$smallestdist = $userdist;
// Put the name of the winner in var
$winner = $row["brugernavn"];
}
}
}- Thanx
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]