Jump to content

[SOLVED] If statments trouble


Clancy19

Recommended Posts

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? 

Link to comment
https://forums.phpfreaks.com/topic/176137-solved-if-statments-trouble/
Share on other sites

<?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;
   }
?>

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;
}
   
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.