dirntknow Posted April 16, 2010 Share Posted April 16, 2010 As a noob i'm sure there's good reason why this doesn't work but what i'd like to achieve is when a visitor opens a page it displays 'no organisation selected' and when they select one from a list (that coding works fine so i've left it out!) it puts ?orgname etc into the url...hope that makes sense! ....but this particular bit doesn't work!! Any suggestions most welcome, thanks! <?php if ($_GET['orgname']='') { echo "no organisaton selected"; } else { echo $_GET['orgname']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/198776-basic-ifelse-problem/ Share on other sites More sharing options...
Lamez Posted April 16, 2010 Share Posted April 16, 2010 <?php if(empty($_GET['orgname']) || !isset($_GET['orgname'])) echo "Nothing Selected"; else echo $_GET['orgname']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/198776-basic-ifelse-problem/#findComment-1043227 Share on other sites More sharing options...
Ken2k7 Posted April 16, 2010 Share Posted April 16, 2010 I would put isset before empty. Quote Link to comment https://forums.phpfreaks.com/topic/198776-basic-ifelse-problem/#findComment-1043231 Share on other sites More sharing options...
Lamez Posted April 16, 2010 Share Posted April 16, 2010 I don't think it matters since it is evaluated as a whole to single boolean. Quote Link to comment https://forums.phpfreaks.com/topic/198776-basic-ifelse-problem/#findComment-1043234 Share on other sites More sharing options...
Ken2k7 Posted April 16, 2010 Share Posted April 16, 2010 If something satisfies empty, it'll almost always satisfy isset making the latter almost useless. The only time that's not the case is if the value is null. Quote Link to comment https://forums.phpfreaks.com/topic/198776-basic-ifelse-problem/#findComment-1043243 Share on other sites More sharing options...
Lamez Posted April 16, 2010 Share Posted April 16, 2010 As that may be true, it still does not matter what order they are in. The expression is evaluated as a whole. true || false = true false || false = false false || true = true true || true = true I don't see why the order they are called matters. Quote Link to comment https://forums.phpfreaks.com/topic/198776-basic-ifelse-problem/#findComment-1043246 Share on other sites More sharing options...
Ken2k7 Posted April 16, 2010 Share Posted April 16, 2010 Internally, I'm not sure if it evaluates the entire expression if it's an OR statement. If the first statement evaluates to true, just return true. Why would you bother evaluating the rest? true || anything || anything || ... = true Quote Link to comment https://forums.phpfreaks.com/topic/198776-basic-ifelse-problem/#findComment-1043252 Share on other sites More sharing options...
Lamez Posted April 16, 2010 Share Posted April 16, 2010 I would think the compiler would have to, it has to have someway of detecting first, what kind of expression it is. Only seems logical at that point to evaluate it as a whole. Quote Link to comment https://forums.phpfreaks.com/topic/198776-basic-ifelse-problem/#findComment-1043258 Share on other sites More sharing options...
Ken2k7 Posted April 16, 2010 Share Posted April 16, 2010 Detecting is easy. Just a regular expression. Evaluating is different. Quote Link to comment https://forums.phpfreaks.com/topic/198776-basic-ifelse-problem/#findComment-1043263 Share on other sites More sharing options...
Lamez Posted April 16, 2010 Share Posted April 16, 2010 Detecting is easy. Just a regular expression. Evaluating is different. I could not agree more, I am curious now. I am now going to have to find out. Quote Link to comment https://forums.phpfreaks.com/topic/198776-basic-ifelse-problem/#findComment-1043266 Share on other sites More sharing options...
dirntknow Posted April 16, 2010 Author Share Posted April 16, 2010 Lol, thanks for the swift response guys! Tried it, it works so i'll work out how and why it works so I know for next time!! Quote Link to comment https://forums.phpfreaks.com/topic/198776-basic-ifelse-problem/#findComment-1043286 Share on other sites More sharing options...
Ken2k7 Posted April 16, 2010 Share Posted April 16, 2010 To explain why it doesn't work, it's because of this line: if ($_GET['orgname']='') { When comparing two values, you require at least 2 = signs. The statement you have above is ALWAYS true, because you're setting the value of $_GET['orgname'] to the empty string and that is always true. So there is really no comparison to be done. Quote Link to comment https://forums.phpfreaks.com/topic/198776-basic-ifelse-problem/#findComment-1043291 Share on other sites More sharing options...
dirntknow Posted April 17, 2010 Author Share Posted April 17, 2010 Haha, i'm sure I tried == at some point (along side many other little changes!) but probably had something else amiss as well! Thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/198776-basic-ifelse-problem/#findComment-1043662 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.