php - php没有返回任何回声
问题描述
我有一个表格,它显示来自 mysql 数据库的图书列表和用户可以搜索图书的搜索表单。当用户通过标题和作者的输入值进行搜索时,我期待按标题和作者显示图书列表,并在没有任何记录时显示“NO Books by name or author”作为回显。
我的代码是
<!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%' or title like '%$search%'";
//search with a book name in the table book_info
$result = mysqli_query($db,$query);
?>
<a href="searchform.php" class="btn btn-primary">Go Back</a>
<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
if(mysqli_num_rows($result)>0){
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{ ?>
<tr>
<td colspan="5">
<center>No books found in the library by the name $search </center>
</td>
</tr>
<?php } ?>
</table>
</body>
</html>
<br>
我的搜索表单是
<!DOCTYPE HTML>
<html>
<body bgcolor="87ceeb">
<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>
但是它成功地显示了书籍列表但是当没有任何记录时..它不会启动回声。
附言。如何添加链接按钮,使其显示返回搜索结果以将用户导航到 Searchform,并且用户可以返回上一个表单。
解决方案
您已重复检查“无结果”:
if(mysqli_num_rows($result)>0)if(mysqli_num_rows($result)>0)
删除一个。
推荐阅读
- jquery - 吐司可见但不应该?
- javascript - 我如何才能简单地解决对象中对象中缺少的 JS 属性?
- php - PHP-LARAVEL 6 创建的类别返回 404
- google-apps-script - 如何使用谷歌分析跟踪谷歌表格中的行值发送的电子邮件?
- python - 子列表的唯一元素取决于子列表中的特定值
- environment-variables - Bazel - 如何从环境文件中读取字符串?
- javascript - Service Worker 未收到推送消息
- c# - C# 将对象解析为 Google BigQuery 行
- javascript - 任何机会我都可以用 Apexcharts.js 构建这个径向条
- spring - 弹簧负载产品配置文件