Cornhusker40 Posted June 3, 2010 Share Posted June 3, 2010 echo "Next Increment Number: $next_increment<br><br>"; if ($next_increment <="10") { echo "Chapter 1"; } elseif ($next_increment >="11" || $next_increment <="20") { echo "Chapter 2"; } elseif ($next_increment >="21" || $next_increment <="30") { echo "Chapter 3"; } elseif ($next_increment >="31" || $next_increment <="30") { echo "Chapter 4"; } What I am attempting to do is to obtain the next ID number for the mysql table field and set the chapter field accordingly as per the portion of the script above. Currently the $next_increment = 21, but when I run my script it displays Chapter 2, not Chapter 3? I have checked the tutorials/help, etc. couldn't find any similar situations. Can anyone help me? Tks Link to comment https://forums.phpfreaks.com/topic/203710-help-with-if-elseif/ Share on other sites More sharing options...
mrMarcus Posted June 3, 2010 Share Posted June 3, 2010 because your condition is true where $next_increment >="11" .. 21 is greater than or equal to 11. You probably mean to use && instead of || 'cause right now you have: elseif ($next_increment >="11" OR $next_increment <="20") So, either condition can be true, doesn't have to be both. Link to comment https://forums.phpfreaks.com/topic/203710-help-with-if-elseif/#findComment-1066976 Share on other sites More sharing options...
jd307 Posted June 3, 2010 Share Posted June 3, 2010 Change || to &&. Your IF conditions state $next_increment >= "11" || $next_increment <= "20". This says IF next_increment is morethan or equal to 11, echo Chapter 2. At this point, $next_increment IS more than 11 therefore it displays "Chapter 2" as the line meets the first condition and doesnt have to meet the 2nd one. If you Change || (OR) to && (AND) then it has to be >= 11 AND <= 20. Link to comment https://forums.phpfreaks.com/topic/203710-help-with-if-elseif/#findComment-1066978 Share on other sites More sharing options...
Cornhusker40 Posted June 3, 2010 Author Share Posted June 3, 2010 Tks jd307 - how obvious! Link to comment https://forums.phpfreaks.com/topic/203710-help-with-if-elseif/#findComment-1067150 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.