Mr.Canuck Posted March 31, 2010 Share Posted March 31, 2010 Hey everyone. I had some great help on here so far with this and as a result I have written an if statement so that a part of the code is not executed when a certain page is displayed. So, if you look at the following piece of code, you will see that I want to exclude this code from executing only when the page "products" is displayed. The full URL of that page is: http://store.scrapbookingfanatics.com/index.php?cpage=products For some reason, the div id "rightside" and the "showCart" and "showSidebar" are still being executed when the products page is displayed. It is my understanding that the following if statement should prevent this from happening. Am I missing something?? Thanks, <?php if(!$cpage == "products"){ ?> <div id="rightside"> <?php if($this->showCart()) $this->cartPnl->Render(); ?> <div style="clear: both;"> <?php if($this->showSideBar()) $this->sidePnl->Render(); ?> </div> </div> <?php } ?> </div> Quote Link to comment https://forums.phpfreaks.com/topic/197128-php-if-statement-not-working/ Share on other sites More sharing options...
Wolphie Posted March 31, 2010 Share Posted March 31, 2010 No, the correct way of doing this would be: if ($cpage != 'product') { // code } Quote Link to comment https://forums.phpfreaks.com/topic/197128-php-if-statement-not-working/#findComment-1034751 Share on other sites More sharing options...
Mr.Canuck Posted March 31, 2010 Author Share Posted March 31, 2010 Thanks for the reply. I just did that and it is still not working. The sidebar is still showing up here: http://store.scrapbookingfanatics.com/index.php?cpage=products Quote Link to comment https://forums.phpfreaks.com/topic/197128-php-if-statement-not-working/#findComment-1034756 Share on other sites More sharing options...
zeodragonzord Posted March 31, 2010 Share Posted March 31, 2010 I believed I helped you earlier regarding the conditional for the login page. The logic is the same, similar to what Wolphie has. Notice the !=, meaning 'not equal'. Quote Link to comment https://forums.phpfreaks.com/topic/197128-php-if-statement-not-working/#findComment-1034757 Share on other sites More sharing options...
Mr.Canuck Posted March 31, 2010 Author Share Posted March 31, 2010 Yes, I do understand and I appreciate the clarification. However, now that I have it written correctly, why is it not working? That's what I don't understand. Quote Link to comment https://forums.phpfreaks.com/topic/197128-php-if-statement-not-working/#findComment-1034759 Share on other sites More sharing options...
zeodragonzord Posted March 31, 2010 Share Posted March 31, 2010 Check the spelling of the value you are comparing. I noticed that Wolphie gave an example using "product" but your code has "products". See if that's it. Quote Link to comment https://forums.phpfreaks.com/topic/197128-php-if-statement-not-working/#findComment-1034764 Share on other sites More sharing options...
Mr.Canuck Posted March 31, 2010 Author Share Posted March 31, 2010 Good thought. I double checked and I do have "products" in the code (it matches). Quote Link to comment https://forums.phpfreaks.com/topic/197128-php-if-statement-not-working/#findComment-1034770 Share on other sites More sharing options...
Wolphie Posted March 31, 2010 Share Posted March 31, 2010 Sorry, I wasn't paying complete attention to your code. I noticed the error straight away and thought I'd post without knowing the exact conditions. Quote Link to comment https://forums.phpfreaks.com/topic/197128-php-if-statement-not-working/#findComment-1034776 Share on other sites More sharing options...
Mr.Canuck Posted March 31, 2010 Author Share Posted March 31, 2010 No worries. Thanks for your input. From what I understand, it SHOULD be working now. Not sure what's going on Quote Link to comment https://forums.phpfreaks.com/topic/197128-php-if-statement-not-working/#findComment-1034779 Share on other sites More sharing options...
Mr.Canuck Posted March 31, 2010 Author Share Posted March 31, 2010 Thank you ALL for your help. I had to add: $cpage = $_GET['cpage']; to my code and now it is working! Cheers, Quote Link to comment https://forums.phpfreaks.com/topic/197128-php-if-statement-not-working/#findComment-1034827 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.