我想根据所选的下拉值显示数据库中的记录。我有一个页面显示一个下拉列表名称和另一个下拉列表,显示从第一个下拉列表中所选列的行。之后有一个搜索按钮,它根据这两个下拉菜单显示所有记录,即所选列名和该列的选定行。然后搜索按钮显示包含所有列的表格并显示特定结果。 问题我不知道如何在select查询中使用该下拉列表ID。这是我的代码:
<form id="searchform" action="view.php" method="post" enctype="multipart/form-data" >
<select id="select1" onChange="check(this);">
<option selected value="" disabled="disabled">Select an Option</option>
<option value="all">Select All</option>
<option value="names" >Names</option>
<option value="courses" >Courses</option>
</select>
<select id="select2" disabled="disabled">
<option>Select an option</option>
<?php
$sql="SELECT DISTINCT names FROM table ";
$result = mysqli_query($sql);
while ($row = mysql_fetch_array($result)) {
echo "<option class='names' value=' " . $row['names'] ."'>" . $row['names'] ."</option>";
}
?>
<?php
$sql="SELECT DISTINCT courses FROM table ";
$result = mysqli_query($sql);
while ($row = mysql_fetch_array($result)) {
echo "<option class='courses' value=' " . $row['courses'] ."'>" . $row['courses'] ."</option>";
}
?>
</select>
<input type="submit" name="submit" value="Search" />
</form>
现在在view.php页面上
<body>
<?php
$count=1;
include("connection.php");
$select1=isset($_POST['select1']);
$select2=isset($_POST['select2']);
$result=mysql_query("SELECT names,courses FROM table WHERE names='.$_REQUEST['select2'].'");
echo "<table border='1' cellpadding='10'>";
echo "<tr><th>Names</th> <th>Courses</th></tr>";
while ($row=mysql_fetch_array($result)){?>
<tr>
<td align="center" ><?php echo $row["names"]; ?></td>
<td align="center" ><?php echo $row["courses"]; ?></td>
</tr>
<?php $count++; } ?>
</table>
</body>
</html>