Jump to content


Photo

Else if statements?


  • Please log in to reply
3 replies to this topic

#1 Andrew R

Andrew R
  • Members
  • PipPipPip
  • Advanced Member
  • 158 posts
  • LocationIreland

Posted 17 October 2006 - 04:51 PM

Can anybody tell me why this script below that calculates a pilot rank is not working.  I'm getting a Parse error: parse error, unexpected '<' . As you can see in the else if statement if the 'flthrs' is bigger than 25 but less and 75 it will insert 'First Officer into the database.
How do you write these sort of statements correctly?

if ($user_array['flthrs'] > '25'){ 
$rank = 'Training Officer';
		} else if ($user_array['flthrs'] > '25' & < '75'){ 
		$rank = 'First Officer';
		}

Cheers!

#2 shiny_spoon

shiny_spoon
  • Members
  • PipPip
  • Member
  • 26 posts
  • LocationCanada

Posted 17 October 2006 - 05:05 PM

Your '&' is the problem. Try it like so:

<?php
if ($user_array['flthrs'] > '25'){ 
   $rank = 'Training Officer';
}
elseif ($user_array['flthrs'] > '25' && $user_array['flthrs'] < '75'){ 
   $rank = 'First Officer';
}
?>


#3 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 17 October 2006 - 05:07 PM

Something like...

if ( $user_array['flthrs'] > 25 && $user_array['flthrs'] < 75 )
{ 
	$rank = 'First Officer';
}
else if ( $user_array['flthrs'] > 25 )
{ 
	$rank = 'Training Officer';
}

I reversed them, because your evaluating upper and lower range, so it should be tested before a single limit! It still doesn't make much sense, because training officer is above 25, are sure you don't want it like so...

if ( $user_array['flthrs'] <= 25 ) // less than or equal to
{ 
	$rank = 'Training Officer';
}
else if ( $user_array['flthrs'] > 25 && $user_array['flthrs'] < 75 )
{ 
	$rank = 'First Officer';
}

me!


me!

#4 Andrew R

Andrew R
  • Members
  • PipPipPip
  • Advanced Member
  • 158 posts
  • LocationIreland

Posted 17 October 2006 - 05:41 PM

Thanks printf and shiny_spoon, I want it so that above 25 and less than 75 is First Officer and anything below 25 is Training Officer. 

I'm having a few problems with it though, the ranks only seem to be changing on whole numbers, i.e. training officer wil only change to first officer if hours are 30 or over when I want it to change at 25 or over?  Is there a way I can get around this?

Cheers again.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users