gpt4 book ai didi

php - 缺少从数据库打印的结果

转载 作者:行者123 更新时间:2023-11-29 22:22:40 24 4
gpt4 key购买 nike

我的目的是从输入键盘搜索书籍类型并进行计数。我有错误:计算书的数量是正确的,但打印时,它错过了一些结果。例如,我输入“f”,它显示 7 个结果(右),但它只打印 2 个两个结果。这是我的代码:

<form action="" method="POST">
Enter type of book here:<input type="text" size="20" name="sbt"> <br />
<input type="submit" name="sb" value="Search">
</form>
<table align="center" border="1" width="600">
<thead><tr align="center">
<tr align="center">
<td><b>Book ID</b></td>
<td><b>Book Title</b></td>
<td><b>Book Author</b></td>
<td><b>Pulished Year</b></td>
<td><b>Book Type</b></td>
<td><b>Status</b></td>
</tr>
<?php
if (isset($_POST['sb'])) {
$s="";
if ($_POST['sbt'] == null) {
echo "Please re-enter <br>";
} else
{
$s = $_POST['sbt'];
}
$q = "SELECT * FROM book WHERE book_type LIKE '%$s%' ";
$r= mysqli_query($conn,$q);
while($row = mysqli_fetch_array($r)) {
?>
<tr align="center">
<td><?php echo $row['book_no'];?></td>
<td><?php echo $row['book_title'];?></td>
<td><?php echo $row['book_author'];?></td>
<td><?php echo $row['book_year'];?></td>
<td><?php echo $row['book_type'];?></td>
<td>
<?php
if ($row['book_quantity'] == 1) {
echo "Available";
}
else {
echo "Not available";
}

?>
</td>

<?php
$c=" SELECT COUNT(DISTINCT(book_no)) AS totaltype FROM book WHERE book_type LIKE '%$s%'";
$s= mysqli_query($conn, $c);
if (mysqli_num_rows($s)> 0 )
{
$row2= mysqli_fetch_array($s);
echo " Total book type result:"."{$row2['totaltype']}";
}
}

?>
<?php } ?>
</table>

最佳答案

删除 $s 之前的 "%" 并尝试。

例如:

$query = mysql_query("SELECT * FROM table WHERE the_number LIKE '$yourPHPVAR%'");

关于php - 缺少从数据库打印的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30565365/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com