PHP develops a ...LOGIN

PHP develops a simple book background management system to implement book query function

We have already implemented the new book management paging function of the book backend management system.

The paging function queried here is basically the same as mentioned above.

This section mainly explains the query function and adds the query function to the paging function.

51.png

Use the SQL LIKE operator to search for a specified pattern in a column in the WHERE clause.

Query book information by selecting the type and entering the query fields.

<?php
$SQL = "SELECT * FROM yx_books where ".$_POST['seltype']." like ('%".$_POST['coun']."%')";
?>

Also add the selection type and query input field to the data displayed on each page

<?php
$SQL = "SELECT * FROM yx_books where ".$_POST['seltype']." like ('%".$_POST['coun']."%') order by id desc limit $startno,$pagesize";
?>

Finally, loop out the database query data through the while statement

<?php
while($rows=mysqli_fetch_assoc($rs))
{
   ?>
   <tr align="center">
      <td class="td_bg" width="7%"><?php echo $rows["id"]?></td>
      <td class="td_bg" width="28%" height="26"><?php echo $rows["name"]?></td>
      <td class="td_bg" width="12%" height="26"><?php echo $rows["price"]?></td>
      <td class="td_bg" width="24%" height="26"><?php echo $rows["uploadtime"]?></td>
      <td class="td_bg" width="12%" height="26"><?php echo $rows["type"]?></td>
      <td class="td_bg" width="24%">
         <a href="update.php?id=<?php echo $rows['id'] ?>" class="trlink">修改</a>&nbsp;&nbsp;
         <a href="del.php?id=<?php echo $rows['id'] ?>" class="trlink">删除</a></td>
   </tr>
   <?php
}
?>

The functions of displaying the home page, previous page, next page, and last page at the bottom are basically similar to the previous new book management paging function.

<tr>
   <th height="25" colspan="6" align="center" class="bg_tr">
      <?php
      if($pageno==1)
      {
         ?>
         首页 | 上一页 | <a href="?pageno=<?php echo $pageno+1?>">下一页</a> |
         <a href="?pageno=<?php echo $_POST['seltype']?>">末页</a>
         <?php
      }
      else if($pageno==$pagecount)
      {
         ?>
         <a href="?pageno=1">首页</a> | <a href="?pageno=<?php echo $pageno-1?>">上一页</a> | 下一页 | 末页
         <?php
      }
      else
      {
         ?>
         <a href="?pageno=1">首页</a> | <a href="?pageno=<?php echo $pageno-1?>">上一页</a> |
         <a href="?pageno=<?php echo $pageno+1?>" class="forumRowHighlight">下一页</a> |
         <a href="?pageno=<?php echo $pagecount?>">末页</a>
         <?php
      }
      ?>
      &nbsp;页次:<?php echo $pageno ?>/<?php echo $pagecount ?>页&nbsp;共有<?php echo $recordcount?>条信息 </th>
</tr>


Next Section
<?php $pagesize = 8; //每页显示数 $sql = "select * from yx_books where ".$_POST['seltype']." like ('%".$_POST['coun']."%')"; $rs=mysqli_query($link,$sql) or die("请输入查询条件!!!"); $recordcount=mysqli_num_rows($rs); //mysql_num_rows() 返回结果集中行的数目。此命令仅对 SELECT 语句有效。 $pagecount=($recordcount-1)/$pagesize+1; //计算总页数 $pagecount=(int)$pagecount; $pageno = $_GET["pageno"]; //获取当前页 if($pageno=="") { $pageno=1; //当前页为空时显示第一页 } if($pageno<1) { $pageno=1; //当前页小于第一页时显示第一页 } if($pageno>$pagecount) { $pageno=$pagecount; //当前页数大于总页数时显示总页数 } $startno=($pageno-1)*$pagesize; //每页从第几条数据开始显示 $sql="select * from yx_books where ".$_POST['seltype']." like ('%".$_POST['coun']."%') order by id desc limit $startno,$pagesize"; $rs=mysqli_query($link,$sql); ?>
submitReset Code
ChapterCourseware