【发布时间】:2014-02-12 05:57:08
【问题描述】:
我希望从 php 变量中的“list_cust_name”中选择的项目通过在 WHERE 子句中传递该 php 变量来通过该 sql 查询获取另一个下拉列表“list_cust_city”中的值..这是我的代码..请帮助我..
<td width="228">
<label style="color:#000">Name </label>
<?php
$query_name = "SELECT DISTINCT cust_name FROM customer_db ORDER BY cust_name"; //Write a query
$data_name = mysql_query($query_name); //Execute the query
?>
<select id="list_cust_name" name="list_cust_name">
<?php
while($fetch_options_name = mysql_fetch_assoc($data_name)) { //Loop all the options retrieved from the query
?>
<option value="<?php echo $fetch_options_name['cust_name']; ?>"><?php echo $fetch_options_name['cust_name']; ?></option>
<?php
}
?>
</select>
</td>
<td width="250">
<label style="color:#000">City </label>
<?php
$query_city = "SELECT DISTINCT cust_city FROM customer_db ORDER BY cust_city"; //Write a query
$data_city = mysql_query($query_city); //Execute the query
?>
<select id="list_cust_city" name="list_cust_city">
<?php
while($fetch_options_city = mysql_fetch_assoc($data_city)) { //Loop all the options retrieved from the query
?>
<option value="<?php echo $fetch_options_city['cust_city']; ?>"><?php echo $fetch_options_city['cust_city']; ?></option>
<?php
}
?>
</select>
</td>
【问题讨论】:
-
无法解决您的实际问题...
-
您要在此处刷新页面吗?或@Jokey 建议您在这里需要 ajax 来实现此目标
-
如果我选择 list_cust_name 则不刷新,那么 list_cust_city 将自动出现选项
标签: php mysql sql drop-down-menu selecteditem