Jump to content

Recommended Posts

Hi

 

I have three dependant drop down menus, which gets thier values from a database on refresh, dependant on the selection of the menu above. How can i keep the selected values? Because on refresh, the menus goes back to the first selection.

 

Example can be seen at: http://peugeot.websitewelcome.com/~perfect/Untitled-1.php  At the momment, only Auckland > Auckland City works.

 

code:

 

<?php require_once('Connections/admin.php'); ?>
<?php

mysql_select_db($database_admin, $admin);
$query_regions = "SELECT * FROM regions ORDER BY regions.regionName ASC";
$regions = mysql_query($query_regions, $admin) or die(mysql_error());
$row_regions = mysql_fetch_assoc($regions);
$totalRows_regions = mysql_num_rows($regions);

mysql_select_db($database_admin, $admin);
$query_districts = "SELECT * FROM districts WHERE districts.regionID = '$regions_id'  ORDER BY districts.districtName ASC";
$districts = mysql_query($query_districts, $admin) or die(mysql_error());
$row_districts = mysql_fetch_assoc($districts);
$totalRows_districts = mysql_num_rows($districts);

mysql_select_db($database_admin, $admin);
$query_suburbs = "SELECT * FROM suburbs WHERE suburbs.districtID = '$districts_id' ORDER BY suburbs.suburbName ASC";
$suburbs = mysql_query($query_suburbs, $admin) or die(mysql_error());
$row_suburbs = mysql_fetch_assoc($suburbs);
$totalRows_suburbs = mysql_num_rows($suburbs);
?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<form action="Untitled-1.php" method="get">
<table width="285" border="0" cellspacing="0" cellpadding="2">
<tr class="formtext">
<td>
<select name="regions_id" onchange="this.form.submit()" class="searchformlong">
<option value="">All Regions</option>
<?php
do {  
?>
<option value="<?php echo $row_regions['regionID']?>"><?php echo $row_regions['regionName']?></option>
<?php
} while ($row_regions = mysql_fetch_assoc($regions));
  $rows = mysql_num_rows($regions);
  if($rows > 0) {
      mysql_data_seek($regions, 0);
  $row_regions = mysql_fetch_assoc($regions);
  }
?>
</select></td>
</tr>
<tr class="formtext">
<td><select name="districts_id" class="searchformlong" onchange="this.form.submit()">
<option value="">All Districts</option>
<?php
do {  
?>
<option value="<?php echo $row_districts['districtID']?>"><?php echo $row_districts['districtName']?></option>
<?php
} while ($row_districts = mysql_fetch_assoc($districts));
  $rows = mysql_num_rows($districts);
  if($rows > 0) {
      mysql_data_seek($districts, 0);
  $row_districts = mysql_fetch_assoc($districts);
  }
?>
</select></td>
</tr>
<tr class="formtext">
<td><select name="suburbs_id" class="searchformlong">
<option value="">All Suburbs</option>
<?php
do {  
?>
<option value="<?php echo $row_suburbs['suburbID']?>"><?php echo $row_suburbs['suburbName']?></option>
<?php
} while ($row_suburbs = mysql_fetch_assoc($suburbs));
  $rows = mysql_num_rows($suburbs);
  if($rows > 0) {
      mysql_data_seek($suburbs, 0);
  $row_suburbs = mysql_fetch_assoc($suburbs);
  }
?>
</select></td>
</tr>
</table>
</form>
Region = <?php echo $regions_id; ?><br>
District = <?php echo $districts_id; ?><br>
Suburb = <?php echo $suburbs_id; ?>

</body>
</html>
<?php
mysql_free_result($regions);

mysql_free_result($districts);

mysql_free_result($suburbs);
?>

Link to comment
https://forums.phpfreaks.com/topic/67359-keeping-menu-selections-on-refresh/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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