PHP開發簡單圖書後台管理系統...LOGIN

PHP開發簡單圖書後台管理系統圖書查詢完整程式碼

引入資料庫檔案config.php檔案

和判斷管理員是否登入的ly_check.php檔案

在HTML頁面中呼叫css.css樣式

建立圖書查詢為select.php檔案

<?php
include("config.php");
require_once('ly_check.php');
?>
<!DOCTYPE html>
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <title>图书查询</title>
   <link rel="stylesheet" href="css.css" type="text/css">
</head>
<body>
<table width="80%" border="0" align="center" cellpadding="2" cellspacing="1" class="table">
   <tr>
      <td width="80%" height="27" valign="top" bgcolor="#FFFFFF" class="bg_tr">&nbsp;后台管理&nbsp;>>&nbsp;图书查询</td>
   <tr>
      <td height="27" valign="top" bgcolor="#FFFFFF" class="bg_tr">
         <form id="form1" name="form1" method="post" action="" style="margin:0px; padding:0px;">
            <table width="45%" height="42" border="0" align="center" cellpadding="0" cellspacing="0" class="bk">
               <tr>
                  <td width="36%" align="center">
                     <select name="seltype" id="seltype">
                        <option value="id">图书序号</option>
                        <option value="name">图书名称</option>
                        <option value="price">图书价格</option>
                        <option value="time">入库时间</option>
                        <option value="type">图书类别</option>
                     </select>
                  </td>
                  <td width="31%" align="center">
                     <input type="text" name="coun" id="coun" />
                  </td>
                  <td width="33%" align="center">
                     <input type="submit" name="button" id="button" value="查询" />
                  </td>
               </tr>
            </table>
          </form>
      </td>
   </tr>
</table>
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC" class="table" >
   <tr>
      <td width="7%" height="35" align="center" bgcolor="#FFFFFF">ID</td>
      <td width="28%" align="center" bgcolor="#FFFFFF">书名</td>
      <td width="12%" align="center" bgcolor="#FFFFFF">价格</td>
      <td width="24%" align="center" bgcolor="#FFFFFF">入库时间</td>
      <td width="12%" align="center" bgcolor="#FFFFFF">类别</td>
      <td width="24%" align="center" bgcolor="#FFFFFF">操作</td>
   </tr>
   <?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);
   ?>
   <?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
   }
   ?>
   <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>
</table>
</body>
</html>

在圖書查詢中的圖書「修改」和「刪除」功能繼續使用

update.php修改頁和del.php刪除頁的PHP功能代碼就可以。

下一節
<?php include("config.php"); require_once('ly_check.php'); ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>图书查询</title> <link rel="stylesheet" href="css.css" type="text/css"> </head> <body> <table width="80%" border="0" align="center" cellpadding="2" cellspacing="1" class="table"> <tr> <td width="80%" height="27" valign="top" bgcolor="#FFFFFF" class="bg_tr"> 后台管理 >> 图书查询</td> <tr> <td height="27" valign="top" bgcolor="#FFFFFF" class="bg_tr"> <form id="form1" name="form1" method="post" action="" style="margin:0px; padding:0px;"> <table width="45%" height="42" border="0" align="center" cellpadding="0" cellspacing="0" class="bk"> <tr> <td width="36%" align="center"> <select name="seltype" id="seltype"> <option value="id">图书序号</option> <option value="name">图书名称</option> <option value="price">图书价格</option> <option value="time">入库时间</option> <option value="type">图书类别</option> </select> </td> <td width="31%" align="center"> <input type="text" name="coun" id="coun" /> </td> <td width="33%" align="center"> <input type="submit" name="button" id="button" value="查询" /> </td> </tr> </table> </form> </td> </tr> </table> <table width="80%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC" class="table" > <tr> <td width="7%" height="35" align="center" bgcolor="#FFFFFF">ID</td> <td width="28%" align="center" bgcolor="#FFFFFF">书名</td> <td width="12%" align="center" bgcolor="#FFFFFF">价格</td> <td width="24%" align="center" bgcolor="#FFFFFF">入库时间</td> <td width="12%" align="center" bgcolor="#FFFFFF">类别</td> <td width="24%" align="center" bgcolor="#FFFFFF">操作</td> </tr> <?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); ?> <?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>   <a href="del.php?id=<?php echo $rows['id'] ?>" class="trlink">删除</a> </td> </tr> <?php } ?> <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 } ?>  页次:<?php echo $pageno ?>/<?php echo $pagecount ?>页 共有<?php echo $recordcount?>条信息 </th> </tr> </table> </body> </html>
章節課件