law Posted May 12, 2008 Share Posted May 12, 2008 Sorry about the ridiculous subject. I have been trying to implement some more features on a website and I'm using some $_GET techniques. Apparently I suck at them tho.. does anyone see whats up with this? if (isset($_GET['page'])) { $page == $_GET['page']; } else { $page == 1; } if ($page == 1){ $homeact = active; } if ($page == 2){ $calact = active; } if ($page == 3){ $aboutact = active; } if ($page == 4){ $comact = active; } if ($page == 5){ $contact = active; } <div id="menu-container"> <ul> echo " <li><a href='./index.php?page=1#Home' title='Welcome! Our home is your home!' class='$homeact'>Home</a></li> <li><a href='./index.php?page=2#Calendar' title='Upcoming Events' class='$calact'>Calendar</a></li> <li><a href='./index.php?page=3#Aboutus' title='Learn About Us' style='width: 8.7em;' class='$aboutact'>About Us</a></li> <li><a href='./index.php?page=4#Community' title='Give back to the CSA' class='$comact'>Community</a></li> <li><a href='./index.php?page=5#Contact' title='Contact Us' style='width: 7em;' class='$contact'>Contact</a></li> </ul> "; The "active" class is supposed to make the button appear "on." Also as a side note.. I can't get $page to print ANYTHING when i try to echo it. Link to comment https://forums.phpfreaks.com/topic/105339-_get-has-gotten-the-best-of-me-again/ Share on other sites More sharing options...
monkeytooth Posted May 12, 2008 Share Posted May 12, 2008 $_GET[''] = snaging a var from a URL $_POST[''] = Snagging a var from a form $var_by_itself... snagging itself from a container in the script.. Link to comment https://forums.phpfreaks.com/topic/105339-_get-has-gotten-the-best-of-me-again/#findComment-539516 Share on other sites More sharing options...
Caesar Posted May 12, 2008 Share Posted May 12, 2008 If using if statements, use elseif. Otherwise, I would suggest using switch() instead. Link to comment https://forums.phpfreaks.com/topic/105339-_get-has-gotten-the-best-of-me-again/#findComment-539517 Share on other sites More sharing options...
Caesar Posted May 12, 2008 Share Posted May 12, 2008 <?php if(isset($_GET['page'])) $page = $_GET['page']; else $page = 1; switch($page) { case 1: //Whatever here break; case 2: //Whatever here break; } ?> By the way...I think your issue has more to do with logic. In your code, you're saying that certain variables are defined ONLY if it's on a certain page number. What if they're not on that page? What part of your code addresses that? Link to comment https://forums.phpfreaks.com/topic/105339-_get-has-gotten-the-best-of-me-again/#findComment-539519 Share on other sites More sharing options...
law Posted May 13, 2008 Author Share Posted May 13, 2008 If using if statements, use elseif. Otherwise, I would suggest using switch() instead. ok ill look up switch() i've never used it before.. and whats the difference in if/if else? is it faster? or just a preference of yours? <?php if(isset($_GET['page'])) $page = $_GET['page']; else $page = 1; switch($page) { case 1: //Whatever here break; case 2: //Whatever here break; } ?> By the way...I think your issue has more to do with logic. In your code, you're saying that certain variables are defined ONLY if it's on a certain page number. What if they're not on that page? What part of your code addresses that? um no the logic is correct if they are not on page 1 through 5 then they are not on a page that shows up in my top menu.. which means the menu does not need to represent it.. this code is purely to tell the menu what button is to be depressed.. Link to comment https://forums.phpfreaks.com/topic/105339-_get-has-gotten-the-best-of-me-again/#findComment-539581 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.