//我需要做一个下拉选择选项,其中第一个选项将选择数据库中的服务,当选择第一个选项时,第二个选项是选择医生服务,它将是另一个查询。在mySQL中,我有服务表,医生表和医生服务表。我希望你能为我解决这个问题,因为我是编程新手。
<?php
include 'dbFunctions.php';
?>
<html>
<head>
<title>Dynamic Dropdown</title>
<script language="javascript">
function setOptions(chosen) {
var selbox = document.myform.doctor_services;
selbox.options.length = 0;
if (chosen == "0") {
selbox.options[selbox.options.length] = new Option('Select first Option','0');
}
<?php
$result = mysql_query("SELECT * FROM service") or die(mysql_error());
while(@($c=mysql_fetch_array($result)))
{
?>
if (chosen == "<?=$c['service_id'];?>") {
<?php
$c_id = $c['service_id'];
$doctorServiceQ = "SELECT ds.doctor_service_id, d.doctor_id, d.doctor_name FROM doctor_services ds,
doctor d, service s WHERE ds.doctor_id = d.doctor_id AND service_id = 'c_id'";
$doctorServiceR = mysqli_query($link, $doctorServiceQ) or die('error');
while(@($m=mysql_fetch_array($doctorServiceR)))
{
?>
selbox.options[selbox.options.length] = new
Option('<?=$m['doctor_name'];?>','<?=$m['doctor_service_id'];?>');
<?php
}
?>
}
<?php
}
?>
}
</script>
</head>
<body>
<form name="myform"><div align="center">
<select name="service" size="1"
onchange="setOptions(document.myform.service.options
[document.myform.service.selectedIndex].value);">
<option value="0" selected>Select a car</option>
<?php
$result = mysql_query("SELECT * FROM service") or die(mysql_error());
while(@($r=mysql_fetch_array($result)))
{
?>
<option value="<?=$r['service_id'];?>"><?=$r['service_name'];?></option>
<?php
}
?>
</select><br><br>
<select name="doctor_services" size="1">
<option value=" " selected>Select Option</option>
</select><br><br>
<input type="button" name="go" value="Value Selected"
onclick="alert(document.myform.doctor_services.options
[document.myform.doctor_services.selectedIndex].value);">
</div></form>
</body>
</html>