php - HTML dependent drop down menu -


i have 2 drop down list in htmk page taking values database.

i want second dropdown menu dependent on value selected on first drop down menu.

i trying insert value of first drop down menu mysql query of second drop down menu wondering how can done.can pls me out our suggest better way implement this.

<?php include './connection.php'; $query1 = "select * cities"; $result1 = mysql_query($query1);  echo '<select name="city" id="city">'; echo '<option value="">select...</option>'; while($row1 = mysql_fetch_assoc($result1)) { echo '<option value="' . $row1['name'] . '">'; echo $row1['name']; echo '</option>';  } echo '</select>';  $query2 = "select * cities_areas city="<value selected in first dropdown      list>"; $result2 = mysql_query($query2);  echo '<select name="area" id="area">'; echo '<option value="">select...</option>'; while($row2 = mysql_fetch_assoc($result2)) { echo '<option value="' . $row2['area'] . '">'; echo $row2['area']; echo '</option>';  } echo '</select>'; ?> 

you must use forms.

<form name='myform'>  <select name="city" id="city" onchange="document.forms['myform'].submit();">   <!--your values db here -->  </select> </form> 

now, in php code write (a):

$query2 = "select * cities_areas city='".mysql_real_escape_string($_request['city'])."'"; 

(a) please, note, mysql_real_escape_string deprecated function , given here example. should use mysql pdo instead.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -