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? Quote 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'; Quote 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 Quote 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; Quote 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! Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.