php, if else not working

Associate
Joined
11 Oct 2008
Posts
268
Im trying to make an if else code that does the following

if experience points is less than 1000 echo 'level 1'

if experience points is greater than 3000 and less than 8000 echo 'level 2'

if experience points is greater than 8000 and less than 16000 echo 'level 3'

if experience points is greater than 16000 and less than 25000 echo 'level 4'

I have the following code but it does nothing, doesnt output anything or give any errors. Can anyone see what I have done wrong?

PHP:
<?php

if ($exp < 1000) {

  echo '1';

} elseif (($exp > 3000) && ($exp < 8000)) {

  echo '2';

} elseif (($exp > 8000) && ($exp < 16000)) {

echo '3';

} elseif (($exp > 16000) && ($exp < 25000)) {

echo '4';

}
?>
 
You could also use a switch() here

PHP:
switch($exp) {
  case ($exp > 1000 && $exp <  2000):
    Do this
    break;
  case ($exp > 2000 && $exp <  4000):
    Do this
    break;
  default :
    Do this
}

regarding your elseif's. Finish with an else. IE if non of the conditions are met. Same as default in the switch scenario
 
What level is someone if they have 2000 XP? :p

Oh, and shouldn't the 'greater than' statements be 'greater than or equal to' aka >= ?
 
Back
Top Bottom