php - Can't view records based on selected drop down values from two drop downs
问题描述
I want to show a record from database based on the selected drop down value. I have a page which shows a drop down having column names and another drop down which shows the rows of that selected column from first drop down. After that there is a search button which shows all the records based on those two drop down menus i.e. the selected column name and selected row of that column. Then the search button shows a table having all the columns and shows that specific result. Problem is I don't know how to use that drop down ids in the select query. Here is my code:
<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>
Now on view.php page
<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>
解决方案
推荐阅读
- reactjs - 如何在给定的代码中使用验证
- algorithm - Djikstra-like算法的优化
- python - 我怎样才能找到这个位置来修复截断的转义
- python - 如何使用 cli 从 aws s3 上传和下载 ipa 文件
- python - 从范围中的每个第 n 个元素在 Dataframe 中创建新列
- html - 双向无限图像滑块
- python - 将 mod_wsgi 安装到 venv 的小问题
- reactjs - 为什么组件要重新渲染两次?
- asp.net-core - net::ERR_CONNECTION_REFUSED 尝试使用 SixLabors.ImageSharp.Web 从 azure blob 容器获取图像时
- azure - 如何将来自 Azure 事件中心(kafka 接口)的事件集成到谷歌云发布/订阅