jr8rdt Posted June 10, 2008 Share Posted June 10, 2008 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 https://forums.phpfreaks.com/topic/109625-drop-down-menu-to-feed-the-next-drop-down-menu-db-driven/ Share on other sites More sharing options...
revraz Posted June 10, 2008 Share Posted June 10, 2008 If you want it dynamic, you need to use Ajax or Javascript. Unless you want to use Submit buttons. Link to comment https://forums.phpfreaks.com/topic/109625-drop-down-menu-to-feed-the-next-drop-down-menu-db-driven/#findComment-562346 Share on other sites More sharing options...
Asheeown Posted June 10, 2008 Share Posted June 10, 2008 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 https://forums.phpfreaks.com/topic/109625-drop-down-menu-to-feed-the-next-drop-down-menu-db-driven/#findComment-562351 Share on other sites More sharing options...
revraz Posted June 10, 2008 Share Posted June 10, 2008 Or you can just look in the FAQ area http://www.phpfreaks.com/forums/index.php/topic,155984.0.html Link to comment https://forums.phpfreaks.com/topic/109625-drop-down-menu-to-feed-the-next-drop-down-menu-db-driven/#findComment-562360 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.