aebstract Posted October 6, 2006 Share Posted October 6, 2006 I really didn't want to have to ask for help but it's late, and I can't seem to find the problem.. which is retarded. It's probably something dumb. I have a very simple elseif statement for my tab navigation (since I can't think of another way to set the active tab). All it has to do is take the variable from the url and check through the if statements, finding the correct one and bam. For some reason it doesn't want to work, can anyone take a look at my code and the site and tell me whats going on? Thanks in advance!http://www.carbenco.com/uy/[code]<?phpif ($page == about) {echo ' <ul id="navlist"> <li><a href="index.php">Home</a></li> <li class="active"><a href="index.php?page=about">About</a></li> <li><a href="index.php?page=gallery">Gallery</a></li> <li><a href="index.php?page=contact">Contact</a></li> </ul>';} elseif ($page == gallery) {echo ' <ul id="navlist"> <li><a href="index.php">Home</a></li> <li><a href="index.php?page=about">About</a></li> <li class="active"><a href="index.php?page=gallery">Gallery</a></li> <li><a href="index.php?page=contact">Contact</a></li> </ul>';} elseif ($page == contact) {echo ' <ul id="navlist"> <li><a href="index.php">Home</a></li> <li><a href="index.php?page=about">About</a></li> <li><a href="index.php?page=gallery">Gallery</a></li> <li class="active"><a href="index.php?page=contact">Contact</a></li> </ul>';} else {echo ' <ul id="navlist"> <li class="active"><a href="index.php">Home</a></li> <li><a href="index.php?page=about">About</a></li> <li><a href="index.php?page=gallery">Gallery</a></li> <li><a href="index.php?page=contact">Contact</a></li> </ul>';}?>[/code] Quote Link to comment Share on other sites More sharing options...
akitchin Posted October 6, 2006 Share Posted October 6, 2006 much more effective ways of doing this:[code]<?phpecho '<ul id="navlist"> <li'.(($page == 'home' || empty($page)) ? ' class="active"' : '').'><a href="index.php">Home</a></li> <li'.(($page == 'about') ? ' class="active"' : '').'><a href="index.php?page=about">About</a></li> <li'.(($page == 'gallery') ? ' class="active"' : '').'><a href="index.php?page=gallery">Gallery</a></li> <li'.(($page == 'contact') ? ' class="active"' : '').'><a href="index.php?page=contact">Contact</a></li> </ul>';?>[/code]the reason yours didn't work is most likely because you aren't encasing your comparison string (ie. "about" etc.) in single quotes. without using quotes, PHP thinks that the comparison is a constant, not a string.look up strings and the ternary operator, which i've used here. Quote Link to comment Share on other sites More sharing options...
aebstract Posted October 6, 2006 Author Share Posted October 6, 2006 That code doesn't seem to do the trick either? :-\ Quote Link to comment Share on other sites More sharing options...
akitchin Posted October 6, 2006 Share Posted October 6, 2006 i assumed that you knew about how to access variables when passing by URL. change the $page to $_GET['page'] in case register_globals is not on. read up on register_globals. 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.