Andrew R Posted October 17, 2006 Share Posted October 17, 2006 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! Quote Link to comment Share on other sites More sharing options...
shiny_spoon Posted October 17, 2006 Share Posted October 17, 2006 Your '&' is the problem. Try it like so:[code]<?phpif ($user_array['flthrs'] > '25'){ $rank = 'Training Officer';}elseif ($user_array['flthrs'] > '25' && $user_array['flthrs'] < '75'){ $rank = 'First Officer';}?>[/code] Quote Link to comment Share on other sites More sharing options...
printf Posted October 17, 2006 Share Posted October 17, 2006 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! Quote Link to comment Share on other sites More sharing options...
Andrew R Posted October 17, 2006 Author Share Posted October 17, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.