realjumper Posted July 19, 2007 Share Posted July 19, 2007 I can't see the forest for the trees today! Can someone expain to me why the following code doesn't work when the the first condition is true and the second condition is false? In this example, health_safety (in the db) is set to 'No'....but investigator is set to 'Yes'? To my way of thinking the statement is saying "if health_safety is not equal to 'Yes' OR investigator is not is not equal to 'Yes' echo "Go Away". So the example should read (according to the db) "health_safety = 'No' but investigator = 'Yes'" (therefore) 'Hello' if ($row[health_safety] != 'Yes' || $row[investigator] != 'Yes') { echo "Go Away"; exit()' } else{ echo "Hello"; } Link to comment https://forums.phpfreaks.com/topic/60878-solved-if-statement-question/ Share on other sites More sharing options...
Caesar Posted July 19, 2007 Share Posted July 19, 2007 Does this yield different results..... <?php if ($row[health_safety] == 'Yes' || $row[investigator] == 'Yes') { echo "hello"; } else { echo "I hate your face. Die."; exit; } ?> Also...you did print out the values to see if they were outputting 'Yes' or 'No', right? Link to comment https://forums.phpfreaks.com/topic/60878-solved-if-statement-question/#findComment-302901 Share on other sites More sharing options...
realjumper Posted July 19, 2007 Author Share Posted July 19, 2007 Thanks Caesar....the 'if' statement works as you have it....but if neither condition is true ie I set both 'health_safety' and 'investigator' to "No" in the db, then the else staement doesn't work....in fact I just get a white page. Yes I did print out the values and they are fine :-) Link to comment https://forums.phpfreaks.com/topic/60878-solved-if-statement-question/#findComment-302904 Share on other sites More sharing options...
realjumper Posted July 19, 2007 Author Share Posted July 19, 2007 Update: You are correct Caesar,,,, I had an error further on down the page which was giving me the white page....sorry....it's 'one of those days'. Many thanks :-) Link to comment https://forums.phpfreaks.com/topic/60878-solved-if-statement-question/#findComment-302906 Share on other sites More sharing options...
Caesar Posted July 20, 2007 Share Posted July 20, 2007 Glad you've got it figured out. Happy coding Link to comment https://forums.phpfreaks.com/topic/60878-solved-if-statement-question/#findComment-302915 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.