Clancy19 Posted October 1, 2009 Share Posted October 1, 2009 Can someone please help me fix this coding. if ($total=="'10' "or" '9'") { echo "<td><p><font face=arial color=red size=7>Excellent <br></font>"; } if ($total=="'8' "or" '7' "or" '6'") { echo "<td><p><font face=arial color=red size=7>Great <br></font>"; } if ($total=="'5' "or" '4' ") { echo "<td><p><font face=arial color=red size=7>Good <br></font>"; } if ($total=="'3' "or" '2' "or" '1' "or" '0'") { echo "<td><p><font face=arial color=red size=7>Better Luck Next Time <br></font>"; } When I use this code it echos everything, no matter what $total is. How can i make this work so it only echos one statement depending on what $total is? Quote Link to comment https://forums.phpfreaks.com/topic/176137-solved-if-statments-trouble/ Share on other sites More sharing options...
Alex Posted October 1, 2009 Share Posted October 1, 2009 The syntax is: if($total == 5 || $total == 10) { } Etc.. Quote Link to comment https://forums.phpfreaks.com/topic/176137-solved-if-statments-trouble/#findComment-928154 Share on other sites More sharing options...
redarrow Posted October 1, 2009 Share Posted October 1, 2009 <?php $total=5; if ($total== 10 || $total==9) { echo "<td><p><font face=arial color=red size=7>Excellent <br></font>"; exit; } if($total== 8 || $total== 7 || $total== 6 ) { echo "<td><p><font face=arial color=red size=7>Great <br></font>"; exit; } if ($total== 5 ||$total==4 ) { echo "<td><p><font face=arial color=red size=7>Good <br></font>"; exit; } if ($total== 3 || $total==2 || $total== 1 || $total==0 ) { echo "<td><p><font face=arial color=red size=7>Better Luck Next Time <br></font>"; exit; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/176137-solved-if-statments-trouble/#findComment-928157 Share on other sites More sharing options...
redarrow Posted October 1, 2009 Share Posted October 1, 2009 with a switch . <?php $total=5; switch ($total){ case 10: case 9: { echo "<td><p><font face=arial color=red size=7>Excellent <br></font>"; exit; } case 8: case 7: case 6: { echo "<td><p><font face=arial color=red size=7>Great <br></font>"; exit; } case 5: case 4: { echo "<td><p><font face=arial color=red size=7>Good <br></font>"; exit; } case 3: case 2: case 1: case 0: { echo "<td><p><font face=arial color=red size=7>Better Luck Next Time <br></font>"; exit; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/176137-solved-if-statments-trouble/#findComment-928160 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.