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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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