...

View Full Version : Query Strings - Probably something obvious



fl00d
07-01-2007, 04:29 AM
ok... another thing. I'm trying to make a navigation bar.
This is my current 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

Dirt Jumps
Park
Urban

When just ONE is clicked;

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 :)

_Aerospace_Eng_
07-01-2007, 04:46 AM
You need to check the value of the get.

if(isset($_GET['category']) && $_GET['category'] == 'dirtjump')

rjoiram
07-01-2007, 04:48 AM
If I understand what you're asking correctly then you can try this:



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

fl00d
07-01-2007, 04:57 AM
aha! Thank you guys so much :D 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 :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum