vbcoach Posted June 11, 2012 Share Posted June 11, 2012 Hello all. Having trouble with doing an IF statement using a math operator. Seems simple enough, but I keep getting a syntax error. I have a sports league, who's fees are based upon the number of (extra) players on a team. $intPlayers is a variable number derived by a loop of the number of registered players on a given team. $intBsize is the base league size given based upon the league registered (2, 4, or 6) I am trying to come up with a mathmetical PHP statement that will determine if the number of (extra) players over the "base" number. Once that happens, I can charge a fee per player over the team base amount allowed. For example, if a 6's league registers 8 players, they need to pay for those additonal two players. So here is my code with the syntax error: $plyrCount = $intPlayers - $intBsize {if $plyrCount<0 then $plyrCount = '0'} $xtraPlyrs = ($plyrCount * 40) I have tried a bunch of variations, but nothing seems to work. If the value of $plyrCount is a negative number, then set $plyrCount to zero. Can anyone help please? Link to comment https://forums.phpfreaks.com/topic/263974-math-using-if-statement-syntax-error/ Share on other sites More sharing options...
smoseley Posted June 11, 2012 Share Posted June 11, 2012 if ($plyrCount<0) $plyrCount = '0'; Link to comment https://forums.phpfreaks.com/topic/263974-math-using-if-statement-syntax-error/#findComment-1352824 Share on other sites More sharing options...
vbcoach Posted June 11, 2012 Author Share Posted June 11, 2012 Still getting syntax error Link to comment https://forums.phpfreaks.com/topic/263974-math-using-if-statement-syntax-error/#findComment-1352836 Share on other sites More sharing options...
smoseley Posted June 11, 2012 Share Posted June 11, 2012 $plyrCount = $intPlayers - $intBsize; if ($plyrCount<0) $plyrCount = 0; $xtraPlyrs = $plyrCount * 40; Link to comment https://forums.phpfreaks.com/topic/263974-math-using-if-statement-syntax-error/#findComment-1352837 Share on other sites More sharing options...
vbcoach Posted June 11, 2012 Author Share Posted June 11, 2012 That worked, thanks! (now I am getting an undefined variable message - more digging) Thanks! Link to comment https://forums.phpfreaks.com/topic/263974-math-using-if-statement-syntax-error/#findComment-1352840 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.