Jump to content

Else if statements?


Andrew R

Recommended Posts

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?

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

Cheers!
Link to comment
https://forums.phpfreaks.com/topic/24233-else-if-statements/
Share on other sites

Something like...

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

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...

[code]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';
}
[/code]

me!


me!
Link to comment
https://forums.phpfreaks.com/topic/24233-else-if-statements/#findComment-110151
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/24233-else-if-statements/#findComment-110163
Share on other sites

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.