我正在学习使用sql表中的值进行下拉。
我有两个下拉菜单:家庭成员和宗喀格。第一个工作正常,但是第二个下拉菜单无效。我在第二次沉没中使用了相同的代码,但是它不起作用。
enter<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
`enter code here`<title>Add Record Form</title>
</head>
<body>
<form action="addlandac.php" method="post">
<p>
<label for="plotno">Plot no:</label>
<input type="text" name="plotno" id="plotno">
<label for="thramno">Thram No:</label>
<input type="text" name="thramno" id="thramno">
<label for="familyname">Name of family:</label>
<?php include("config_qc.php");
$query="SELECT * FROM familymember_tbl";
$result =mysqli_query($connect,$query);
$options="";
while ($row=mysqli_fetch_array($result,MYSQLI_ASSOC)) {
$famid=$row["familyID"];
$nam=$row["name"];
//$options.="<OPTION VALUE=\"$dzong\">".$dzong.'-'.$dz_id.'</option>';
$options.="<OPTION VALUE>".$nam.'-'.$famid.'</option>';
}
?>
<select name="family" id="family">
<option value="Select">Select family member</option>
<?=$options?>
//</p>
//<p>
<label for="dz">Dzonkhag:</label>
<?php include("config_qc.php");
$query="SELECT * FROM dzongkhag_tbl";
$result =mysqli_query($connect,$query);
$opt="";
while ($row=mysqli_fetch_array($result,MYSQLI_ASSOC)) {
$dz_id=$row["dzID"];
$dzong=$row["dzname"];
//$options.="<OPTION VALUE=\"$dzong\">".$dzong.'-'.$dz_id.'</option>';
$opt.="<OPTION VALUE>".$dzong.'-'.$dz_id.'</option>';
}
?>
<select name="dz" id="dz">
<option value="Select">Select Dzongkhag</option>
<?=$opt?>
<input type="submit" value="Submit">
</form>
</body>
</html>
<?php
echo "<BR>";
echo"<h4 align=left </h4>";
echo "<BR>";
echo "<a href='menu.php'>Bac to Main page</a>";
?>
答案 0 :(得分:0)
不确定,但是也许您缺少一些封闭的</select>
标签。也许尝试以下方法:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add Record Form</title>
</head>
<body>
<form action="addlandac.php" method="post">
<label for="plotno">Plot no:</label>
<input type="text" name="plotno" id="plotno">
<label for="thramno">Thram No:</label>
<input type="text" name="thramno" id="thramno">
<label for="familyname">Name of family:</label>
<?php include("config_qc.php");
$query="SELECT * FROM familymember_tbl";
$result =mysqli_query($connect,$query);
$options="";
while ($row=mysqli_fetch_array($result,MYSQLI_ASSOC)) {
$famid=$row["familyID"];
$nam=$row["name"];
$options.="<OPTION VALUE>".$nam.'-'.$famid.'</option>';
}
?>
<select name="family" id="family">
<option value="Select">Select family member</option>
<?=$options?>
</select>
<label for="dz">Dzonkhag:</label>
<?php include("config_qc.php");
$query="SELECT * FROM dzongkhag_tbl";
$result =mysqli_query($connect,$query);
$opt="";
while ($row=mysqli_fetch_array($result,MYSQLI_ASSOC)) {
$dz_id=$row["dzID"];
$dzong=$row["dzname"];
$opt.="<OPTION VALUE>".$dzong.'-'.$dz_id.'</option>';
}
?>
<select name="dz" id="dz">
<option value="Select">Select Dzongkhag</option>
<?=$opt?>
</select>
<input type="submit" value="Submit">
</form>
<?php
echo "<BR>";
echo"<h4 align=left </h4>";
echo "<BR>";
echo "<a href='menu.php'>Bac to Main page</a>";
?>
</body>
</html>
或类似的东西
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add Record Form</title>
</head>
<body>
<form action="addlandac.php" method="post">
<label for="plotno">Plot no:</label>
<input type="text" name="plotno" id="plotno">
<label for="thramno">Thram No:</label>
<input type="text" name="thramno" id="thramno">
<label for="familyname">Name of family:</label>
<?php
include("config_qc.php");
$query="SELECT * FROM familymember_tbl";
$result =mysqli_query($connect,$query);
$options="";
while ($row=mysqli_fetch_array($result,MYSQLI_ASSOC)) {
$famid=$row["familyID"];
$nam=$row["name"];
$options.="<option value="'.$nam.'-'.$famid.'">"'.$nam.'-'.$famid.'"</option>";
}
?>
<select name="family" id="family">
<option value="Select family member">Select family member</option>
<?=$options?>
</select>
<label for="dz">Dzonkhag:</label>
<?php
include("config_qc.php");
$query="SELECT * FROM dzongkhag_tbl";
$result =mysqli_query($connect,$query);
$opt="";
while ($row=mysqli_fetch_array($result,MYSQLI_ASSOC)) {
$dz_id=$row["dzID"];
$dzong=$row["dzname"];
$opt.="<option value="'.$dzong.'-'.$dz_id.'">"'.$dzong.'-'.$dz_id.'"</option>";
}
?>
<select name="dz" id="dz">
<option value="Select Dzongkhag">Select Dzongkhag</option>
<?=$opt?>
</select>
<input type="submit" value="Submit">
</form>
<?php echo "<br><h4 align=left </h4><br><a href='menu.php'>Back to main page</a>"; ?>
</body>
</html>