我有两个下载列表由数据库填充php,问题是我希望根据第一个选择的值填写第二个下拉列表,但我不知道如何这样做......这是我的代码:
<div class="users">
<h1>Choose the user</h1>
<div id="select">
table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="50%">Name:</th>
<th width="50%"><div class="drops">
<label>
<select>
<?php
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name
$dbh= mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql = mysql_query("SELECT User FROM $tbl_name");
while ($row = mysql_fetch_array($sql)){
echo "<option value=\"owner1\">" . $row['User'] . "</option>";
}
?>
</select>
</label>
</th>
</tr>
</table>
</div>
<h1>N3- Second Option</h1>
<form class="form1" name="form1" method="post" action="addSuc.php">
<div id="selectoresDrop">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="5%">Second:</th>
<th width="95%"><div class="drops">
<label>
<select>
<?php
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl2_name=""; // Table name
$dbh= mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql = mysql_query("SELECT Second FROM $tbl2_name WHERE ID_User=??????");
while ($row = mysql_fetch_array($sql)){
echo "<option value=\"owner1\">" . $row['Second'] . "</option>";
}
?>
</select>
</label>
</th>
</tr>
</table>
</div>
正如您所看到的,当填写第二个下拉列表时,我有一个SQL语句,我说&#34; SELECT Second FROM $ tbl2_name WHERE ID_User = ??????&#34;,我想要这句话要做的是,如果第一个下拉列表的第一个元素被选中,则它等于“1”,而第二个“&#39; 2&#39;等等...
有人知道我该怎么办?