I have build two drop downs (like state and city) by fetching the records of both drop downs from mysql database and am trying to build the tool in which, while selecting any value (i.e. any state) from first drop down, at that time in second drop down (in city) only those values (cities) under that value (state) selected in first drop down should be visible.
Here's my code:
<tr>
<td id='hed'><span style="font-family:verdana,geneva,sans- serif">State</state></td>
<td>
<?php
$dbcon = mysql_connect("@ip","@username","@password");
if($dbcon)
{
mysql_select_db("@database", $dbcon);
}
else
{
die('error connecting to the database');
}
$qry = "select @value(state) from @tablename ";
$result = mysql_query($qry) or die(mysql_error());
$dropdown = "<select name='@valuename' id='officeItemList' style='cursor:pointer;cursor:hand;'>";
while($row = mysql_fetch_array($result))
{
$dropdown .= "
<option value='{$row['@value']}' > {$row['@value']} </option>";
}
$dropdown .= "
</select>";
echo $dropdown;
mysql_close($dbcon);
?>
</td>
</tr>
<tr>
<td id='hed'><span style="font-family:verdana,geneva,sans-serif">City</span></td>
<td colspan="1">
<?php
$dbcon = mysql_connect("@ip","@username","@password");
if($dbcon)
{
mysql_select_db("@database", $dbcon);
}
else
{
die('error connecting to the database');
}
$qry = "select value2(city) from @tablename where ";
$result = mysql_query($qry) or die(mysql_error());
$dropdown = "<select name='@value2' id='officeItemList' style='cursor:pointer;cursor:hand;'>";
while($row = mysql_fetch_array($result))
{
$dropdown .= "
<option value='{$row['@value2']}' > {$row['@value2']} </option>";
}
$dropdown .= "
</select>";
echo $dropdown;
mysql_close($dbcon);
?>
</td>
</tr>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…