Jump to content

Drop down menu to feed the next drop down menu db driven


jr8rdt

Recommended Posts

Hello

 

I want to be able to use different sql statement based on the select option from the same form.

a Venue has a single Region

a Region has multiple Venues

 


<tr>
   <td>Region</td>
   <td>
   <select name="Region">
       <option value="r1">Region1</option>
       <option value="r1">Region2</option>
       <option value="r3">Region3</option>
       
      </select>
   </td>
   
</tr>

tr><td>Venue</td>
	<td><select name="Venue">

	<?php
	$query_venue = "SELECT name FROM venue group by name ASC";
                $result_venue = mysql_query($query_venue);

                while($row_venue = mysql_fetch_assoc($result_venue))
                {
                        echo "<option value =\"".$row_venue['name']."\">".ucfirst($row_venue['name'])."</option>";
                }
	?>
	</select></td></tr>

<tr>

Link to comment
Share on other sites

Here I made this in about 2 seconds so their might be errors, let me know, it uses a javascript jumpmenu

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <label>
  <select name="select" id="select">
  </select>
  <select name="Region" id="Region" onchange="MM_jumpMenu('parent',this,0)">
    <option value="<?php echo $PHP_SELF; ?>?Region=1">Region 1</option>
    <option value="<?php echo $PHP_SELF; ?>?Region=2">Region 2</option>
    <option value="<?php echo $PHP_SELF; ?>?Region=3">Region 3</option>
    </select>
  </label>
</form>
<?php
if($_GET['Region']) {
?>
<select name="Venue">
	<?php
	$query_venue = "SELECT name FROM venue group by name ASC WHERE region = '".$_GET['Region']."'";
                $result_venue = mysql_query($query_venue);

                while($row_venue = mysql_fetch_assoc($result_venue))
                {
                        echo "<option value =\"".$row_venue['name']."\">".ucfirst($row_venue['name'])."</option>";
                }
	?>
	</select>
<?php
}
?>
</body>
</html>

 

 

When an option is selected it goes to the current page (i.e. test.php) test.php?Region=1

1-3 are the options I put in there, you can put other ones, then it pulls the SQL with a where statement of "Region = '".$_GET['Region']."'

Link to comment
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.