SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: Dynamic menu question
-
May 18, 2003, 04:01 #1
- Join Date
- Oct 2001
- Location
- Helston, Cornwall, England
- Posts
- 76
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Dynamic menu question
Hi all,
I am playing with a multiple dynamic dropdown menu in a form based on a MySQL db, where the 2nd menu populates on a selection from the first with an onchange() submit. I have used DW MX/php to create the menu and it works fine....but. My question is how can I get the 1st menu to show what was selected after the initial submit? At present it just reverts to the first option on the list.
The select bit:
PHP Code:mysql_select_db($database_login, $login);
$query_rs_areas = "SELECT DISTINCT area FROM choosespain WHERE country = 'spain' ORDER BY choosespain.area";
$rs_areas = mysql_query($query_rs_areas, $login) or die(mysql_error());
$row_rs_areas = mysql_fetch_assoc($rs_areas);
$totalRows_rs_areas = mysql_num_rows($rs_areas);
$colname_rs_town = "1";
if (isset($HTTP_POST_VARS['area'])) {
$colname_rs_town = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS['area'] : addslashes($HTTP_POST_VARS['area']);
}
mysql_select_db($database_login, $login);
$query_rs_town = sprintf("SELECT DISTINCT town FROM choosespain WHERE area = '%s' ORDER BY choosespain.town", $colname_rs_town);
$rs_town = mysql_query($query_rs_town, $login) or die(mysql_error());
$row_rs_town = mysql_fetch_assoc($rs_town);
$totalRows_rs_town = mysql_num_rows($rs_town);
PHP Code:<form name="form1" method="post" action="autoform2.php">
<select name="area" id="area" onChange="form1.submit()">
<option value="any">Any</option>
<?php
do {
?>
<option value="<?php echo $row_rs_areas['area']?>"><?php echo $row_rs_areas['area']?></option>
<?php
} while ($row_rs_areas = mysql_fetch_assoc($rs_areas));
$rows = mysql_num_rows($rs_areas);
if($rows > 0) {
mysql_data_seek($rs_areas, 0);
$row_rs_areas = mysql_fetch_assoc($rs_areas);
}
?>
</select>
<select name="select">
<option value="any">Any</option>
<?php
do {
?>
<option value="<?php echo $row_rs_town['town']?>"><?php echo $row_rs_town['town']?></option>
<?php
} while ($row_rs_town = mysql_fetch_assoc($rs_town));
$rows = mysql_num_rows($rs_town);
if($rows > 0) {
mysql_data_seek($rs_town, 0);
$row_rs_town = mysql_fetch_assoc($rs_town);
}
?>
</select>
</form>
Warren
-
May 18, 2003, 10:31 #2
- Join Date
- Mar 2002
- Location
- Perth, Australia
- Posts
- 157
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I hope it's this simple:
Make your PHP code output HTML along these lines:
PHP Code:<?php ?>
<SELECT>
<OPTION VALUE="1">Option 1</OPTION>
<OPTION VALUE="2">Option 2</OPTION>
<OPTION VALUE="3" SELECTED>Option 3</OPTION>
<OPTION VALUE="4">Option 4</OPTION>
<OPTION VALUE="5">Option 5</OPTION>
<OPTION VALUE="6">Option 6</OPTION>
</SELECT>
<?php ?>Paul Davey
webmaster for Whitford Church of Christ
-
May 18, 2003, 11:30 #3
- Join Date
- Oct 2001
- Location
- Helston, Cornwall, England
- Posts
- 76
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Bookmarks