I've got most of my page working but I need to make sure variables that have previously been assigned are being passed thru to the URL. For example if a user clicks on a State, then a City, I want the value for City to be appended to the URL along with the value for the State. Then if they click on a category that will be added as well. Ideally I would like to get the same info into the URL regardless of of the order in which the links are clicked.
Ex: www.mysite.com/index.php?State=Alabama&City=Auburn&Category=Dogs
Can anyone help me out?
Here's my code:
<html>
<head>
<title>Site Title</title>
</head>
<body>
<table>
<tr>
<td valign="top">
<a href="<?=$SERVER['PHP_SELF']?>?state=Alabama">Alabama</a><br>
<a href="<?=$SERVER['PHP_SELF']?>?state=Alaska">Alaska</a><br>
<a href="<?=$SERVER['PHP_SELF']?>?state=Arizona">Arizona</a><br>
<br>
<a href="<?=$SERVER['PHP_SELF']?>?category=Dogs">Dogs</a><br>
<a href="<?=$SERVER['PHP_SELF']?>?category=Cats">Cats</a><br>
<a href="<?=$SERVER['PHP_SELF']?>?category=Fish">Fish</a><br>
</td>
<br>
<td valign="top">
<?php
// initialize the variables
$state = !empty($GET['state']) ? $state = $GET['state'] : $state = '';
$city = !empty($GET['city']) ? $city = $GET['city'] : $city = '';
$category = !empty($GET['category']) ? $category = $GET['category'] : $category = '';
// show content based on state selection
switch($state)
{
case "Alabama" :
print '<b>Alabama</b><br>';
include ('alCityLinks.php');
break;
case "Alaska" :
print '<b>Alaska</b><br>';
include ('CityLinks.php');
break;
case "Arizona" :
print '<b>Arizona</b><br>';
include ('CityLinks.php');
break;
default :
break;
}
// show content based on city selection
switch($city)
{
case "Auburn" :
print '<b>You are at Auburn</b><br>';
break;
case "Bessemer" :
print '<b>You are at Bessemer</b><br>';
break;
case "Birmingham" :
print '<b>You are at Birmingham</b><br>';
break;
default :
break;
}
// show content based on category selection
switch($category)
{
case "Dogs" :
print '<b>You are at Auburn</b><br>';
break;
case "Cats" :
print '<b>You are at Bessemer</b><br>';
break;
case "Fish" :
print '<b>You are at Birmingham</b><br>';
break;
default :
break;
}
?>
</td>
</tr>
</table>
</body>
</html>
alCityLinks.php
<a href="?city=Auburn">Auburn</a><br>
<a href="?city=Bessemer">Bessemer</a><br>
<a href="?city=Birmingham">Birmingham</a><br>