我通过从 mysql 数据库中获取两个下拉列表的记录来构建两个下拉列表(如州和城市),并尝试构建该工具,同时从第一个下拉列表中选择任何值(即任何状态),当时在第二个下拉列表(城市)中,只有在第一个下拉列表中选择的值(州)下的那些值(城市)应该是可见的。
这是我的代码:
<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 .= "\r\n<option value='{$row['@value']}' > {$row['@value']} </option>";
}
$dropdown .= "\r\n</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 .= "\r\n<option value='{$row['@value2']}' > {$row['@value2']} </option>";
}
$dropdown .= "\r\n</select>";
echo $dropdown;
mysql_close($dbcon);
?>
</td>
</tr>