Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Mar 2007
    Location
    Quebec
    Posts
    261
    Thanks
    6
    Thanked 7 Times in 7 Posts

    Query Strings - Probably something obvious

    ok... another thing. I'm trying to make a navigation bar.
    This is my current code.

    PHP Code:
    <?php

    echo "<a href=\"/en/trails/index.php?category=dirtjump\">Dirt Jumps</a><br \>";
        if(isset(
    $_GET['category']))
          {
            include(
    "/home/user/public_html/include/dj.inc");
          }
    echo 
    "<a href=\"/en/trails/index.php?category=park\">Park</a><br \>";      
        if(isset(
    $_GET['category']))
          {
            include(
    "/home/user/public_html/include/park.inc");
          }
    echo 
    "<a href=\"/en/trails/index.php?category=urban\">Urban</a><br \>";
        if(isset(
    $_GET['category']))
          {
            include(
    "/home/user/public_html/include/urban.inc");
          }
    ?>
    Even when I just click one link, the included files of ALL 3 links show up. Example:
    Non-clicked
    Code:
    Dirt Jumps
    Park
    Urban
    When just ONE is clicked;
    Code:
    Dirt Jumps
    hello
    helloPark
    helloUrban
    'Hello' is the single word contained in the the included files for now.
    I understand why its showing all of them... because isset($_GET['category']) HAS been already set, right?

    What I can't think of is an alternative method to prevent this. A switch statement popped into my mind, although I haven't quite figured out yet how I would use that. I'm working on it though. Any suggestions?

    I'm about to go hit up Google and see if I find anything there. Hopefully when I'm done with Google there will be a reply

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You need to check the value of the get.
    Code:
    if(isset($_GET['category']) && $_GET['category'] == 'dirtjump')
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Mar 2005
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If I understand what you're asking correctly then you can try this:

    PHP Code:
    <?php

    echo "<a href=\"/en/trails/index.php?category=dirtjump\">Dirt Jumps</a><br \>";
        if(isset(
    $_GET['category']) && $_GET['category'] == "dirtjump")
          {
            include(
    "/home/user/public_html/include/dj.inc");
          }
    echo 
    "<a href=\"/en/trails/index.php?category=park\">Park</a><br \>";      
        if(isset(
    $_GET['category']) && $GET['category'] == "park")
          {
            include(
    "/home/user/public_html/include/park.inc");
          }
    echo 
    "<a href=\"/en/trails/index.php?category=urban\">Urban</a><br \>";
        if(isset(
    $_GET['category']) && $_GET['category'] == "urban")
          {
            include(
    "/home/user/public_html/include/urban.inc");
          }
    ?>
    EDIT: Oops, when I clicked "post reply" there was no answer. I'm too slow...

  • #4
    Regular Coder
    Join Date
    Mar 2007
    Location
    Quebec
    Posts
    261
    Thanks
    6
    Thanked 7 Times in 7 Posts
    aha! Thank you guys so much However, I DID come up with a theory using a switch statement, but adding that extra line in the if statement is so much easier.

    Thanks guys


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •