My need is,
when i select any state from the state combo box, its appropriate cityname must be displayed in the city combo box.
I have two tables
table 1
state
1. cityid
2. stateid
3. statename
table 2
city
1. stateid
2. cityid
3. cityname
posting my code.....
Code: Select all
<?php
error_reporting(0);
$con = mysql_connect("localhost", "root", "");
$db = mysql_select_db("employee", $con);
$sel = "select stateid, statename from state";
$res = mysql_query($sel);
?>
<html>
<head>
<title>Loading value in combobox from DB</title>
</head>
<body>
<select name="state">
<option value="">Select State</option>
<?php
while($row = mysql_fetch_array($res))
{
?>
<option value="<?=$row['stateid']?>"><?=$row['statename']?></option>
<? } ?>
</select>
<p></p>
<?php
$sel_city = "select stateid, cityid, cityname from city where stateid='".$_REQUEST['state']."'";
?>
<select name="city_id">
<option value="">select city</option>
</select>
</body>
</html>Advance thanks for your help.