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"; } Quote Link to comment 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? Quote Link to comment 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 :-) Quote Link to comment 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 :-) Quote Link to comment 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 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.