我正在创建三个下拉菜单 ,它工作得很好,但我希望第二个下拉列表出现在第一个的选择上,第三个出现在第二个的选择上如果有人可以指导我或给我怎么做我是一个例子,我会很感激
PS:第二个下拉列表或表有一个来自第一个的外键,所以在这里我想根据第一个的选择来填充第二个。
有趣的.inc.php
<?php
require_once('db.inc.php');
function connect(){
mysql_connect(DB_Host, DB_User ,DB_Pass )or die("could not connect to the database" .mysql_error());
mysql_select_db(DB_Name)or die("could not select database");
}
function close(){
mysql_close();
}
function countryQuery(){
$countryData = mysql_query("SELECT * FROM country");
while($record = mysql_fetch_array($countryData)){
echo'<option value="' . $record['country_name'] . '">' . $record['country_name'] . '</option>';
}
}
function specializationQuery(){
$specData = mysql_query("SELECT * FROM specialization");
while($recordJob = mysql_fetch_array($specData)){
echo'<option value="' . $recordJob['specialization_name'] . '">' . $recordJob['specialization_name'] . '</option>';
}
}
function governorateQuery(){
$goverData = mysql_query("SELECT * FROM governorate");
while($recordGover = mysql_fetch_array($goverData)){
echo'<option value="' . $recordGover['governorate_name'] . '">' . $recordGover['governorate_name'] . '</option>';
}
}
?>
索引.php
<?php
require_once('func.inc.php');
connect();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>testDroplistdown</title>
</head>
<body>
<p align="center">
<select name="dropdown">
<?php countryQuery(); ?>
</select>
</p>
<br />
<br />
<p align="center">
<select name="dropdown2">
<?php governorateQuery(); ?>
</select>
</p>
<p align="left">
<select name="dropdown3">
<?php specializationQuery(); ?>
</select>
<?php close(); ?>
</p>
</body>
</html>