I have the following dropdown box that uses PHP query to get it's data. It creates a dropdown with 3 entries: CARS, TRUCKS, TRAINS. After I select an option, it performs a GET
and the PHP updates with that category that is selected. I added a static OPTION with text VIEW BY CATEGORY. If I choose a category and then go back to VIEW BY CATEGORY, I would like all results (CARS, TRUCKS, and TRAINS) to show again.
<form name="form1" action="" method="GET">
<select name="category" onchange="this.form.submit();">
<option value="">View By Category...</option>
<?php while ($rows = mysql_fetch_array($query_category)) { ?>
<?php if(isset($_GET['category'])) { ?>
<option value="<?php echo $rows['category']; ?>" <?php echo $rows['category'] == $category ? 'selected' : '' ?> ><?php echo $rows['category'] ?></option>
<?php } else {?>
<option value="<?php echo $rows['category']; ?>"><?php echo $rows['category'] ?></option>
<?php } ?>
<?php } ?>
</select>
</form>
*EXAMPLE- When I select option CARS, my URL will be http://localhost/edit.php?category=Cars
. When I choose VIEW BY CATEGORY, it becomes http://localhost/edit.php?category=
. Then all of my results disappear. Rather than disappear, I would like all results to show.
<?php
//Establishing Connection with Server
$connection = mysql_connect("localhost", "em", "em");
//Selecting Database
$db = mysql_select_db("em", $connection);
//This checks if variable defined
if(isset($_GET['category'])) {
//If it is, will run query with variable
$category = $_GET['category'];
$query = mysql_query("SELECT * FROM tblClients WHERE tblclients.package = 'standard' AND tblclients.category = '$category' ", $connection);
} else {
//If NOT, will run query without variable
$query = mysql_query("SELECT * FROM tblClients WHERE tblclients.package = 'standard' ", $connection);
}
//Other Queries
$query_featured = mysql_query("SELECT * FROM tblClients WHERE tblclients.package = 'featured'", $connection);
$query_category = mysql_query("SELECT * FROM tblCategory", $connection);
?>