Jump to content

$_GET has gotten the best of me again!


law

Recommended Posts

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

<?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?

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..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.