如何基于php中的下拉菜单值显示结果

时间:2018-11-22 01:32:36

标签: php html

我有php文件,用户可以在其中插入图书信息,另一个php以显示结果,然后是“搜索”表单,用户可以根据标题搜索。

我想在Searchfrom中添加下拉菜单,以便用户可以基于Drop Down中的值进行搜索。

我的插入php表单是

<!DOCTYPE HTML>
<html>
<body bgcolor="87ceeb">
<center><h2>Central Department of Physics</h2></center>
<br>
 
<?php
include("DBConnection.php");
 
$isbn=$_POST["isbn"];
$title=$_POST["title"];
$author=$_POST["author"];
$edition=$_POST["edition"];
$publication=$_POST["publication"];
 
$query = "insert into book_info(isbn,title,author,edition,publication) values('$isbn','$title','$author','$edition','$publication')"; //Insert query to add book details into the book_info table
$result = mysqli_query($db,$query);
 
?>
  aee 
<h3> Book information is inserted successfully </h3>
 
<a href="SearchBooks.php"> To search for the Book information click here </a>
 
</body>
</html>

我的Display php表单是

<!DOCTYPE HTML>
<html>
<body bgcolor="87ceeb">
<center><h2>Central Department of Physics</h2></center>
<br>
<?php
include("DBConnection.php");
$search = isset($_REQUEST["search"]) ?  $_REQUEST["search"] : '';

//
$query = "select ISBN,Title,Author,Edition,Publication from book_info where author like '%$search%'"; //search with a book name in the table book_info
$result = mysqli_query($db,$query);
if(mysqli_num_rows($result)>0)if(mysqli_num_rows($result)>0)
{
?>
<table border="2" align="center" cellpadding="5" cellspacing="5">
<tr>
<th> ISBN </th>
<th> Title </th>
<th> Author </th>
<th> Edition </th>
<th> Publication </th>
</tr>
<?php while($row = mysqli_fetch_assoc($result))
{
?>
<tr>

<td><?php echo $row["ISBN"];?> </td>
<td><?php echo $row["Title"];?> </td>
<td><?php echo $row["Author"];?> </td>
<td><?php echo $row["Edition"];?> </td>

<td><a href="<?php  echo $row["Publication"];?>" target="_blank">Click Me</a></td>
</tr>
<?php
}
}
else
echo "<center>No books found in the library by the name $search </center>" ;
?>
</table>
</body>
</html>
<br>

当前第12行是

$query = "select ISBN,Title,Author,Edition,Publication from book_info where author like '%$search%'";

使得它基于作者的值进行搜索。

搜索表是

<!DOCTYPE HTML>
<html>
<body bgcolor="87ceeb">
<center><h2>Central Department of Physics</h2></center>
<form action = "DisplayBooks.php" method="get">
<br>
<center>Enter the title of the book to be searched :
<input type="text" name="search" size="48">
<br></br>
<input type="submit" value="submit">
<input type="reset" value="Reset">
</center>
<br>
</form>
</body>
</html>

如何在搜索书中添加下拉菜单,以便它根据下拉菜单中的值显示图书。

非常感谢。

0 个答案:

没有答案