php分页代码

来源:互联网 发布:unix socket 和windows 编辑:程序博客网 时间:2024/06/05 06:00

<?php session_start();
   if($_POST[f]){
     $_POST[f]=$_POST[f];
    }else{
       $_POST[f]=$_GET[f];
 }
    if($_POST[key1]){
     $_POST[key1]=$_POST[key1];
    }else{
       $_POST[key1]=$_GET[key1];
 }
     if($_POST[page]){
       $_GET[page]=$_POST[page];
    }
?>
<html>
<head>
<title>图书馆管理系统</title>
<link href="CSS/style.css" rel="stylesheet">
</head>
<body>
<table width="778" border="0" align="center" cellpadding="0" cellspacing="0" class="tableBorder">
  <tr>
    <td>
    <?php include("navigation.php");?>
 </td>
 </tr>
 <td>
 <table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td valign="top" bgcolor="#FFFFFF"><table width="99%" height="510"  border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" class="tableBorder_gray">
  <tr>
    <td height="510" valign="top" style="padding:5px;"><table width="98%"  border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td height="22" valign="top" class="word_orange">当前位置:图书管理 &gt; 图书档案管理 &gt;&gt;&gt;</td>
      </tr>


       <tr>
        <td align="center" valign="top">
    <form  name="form1" method="post" action="">
         <table width="98%" height="38"  border="1" cellpadding="1" cellspacing="0" bordercolor="#FFFFFF" bgcolor="#9ECFEE" class="tableBorder_gray">
  <tr>
    <td align="center">
&nbsp;<img src="Images/search.gif" width="37" height="29"></td>
    <td>&nbsp;&nbsp;请选择查询依据:
      <select name="f" class="wenbenkuang" id="f">
        <option value="<?php echo "b.barcode";?>" <?php if($_POST[f]=='b.barcode'){?> selected<?php }?> >图书编号</option>
        <option value="<?php echo "t.typename";?>" <?php if($_POST[f]=='t.typename'){?> selected<?php }?> >类别</option>
        <option value="<?php echo "b.bookname";?>" <?php if($_POST[f]=='b.bookname'){?> selected<?php }?> >书名</option>
        <option value="<?php echo "b.author";?>" <?php if($_POST[f]=='b.author'){?> selected<?php }?> >作者</option>
        <option value="<?php echo "b.ISBN";?>" <?php if($_POST[f]=='b.ISBN'){?> selected<?php }?> >出版社</option>
        <option value="<?php echo "c.name";?>" <?php if($_POST[f]=='c.name'){?> selected<?php }?> >书架</option>
                  </select>
      <input name="key1" type="text" id="key1" value="<?php echo $_POST[key1];?>" size="50">
   <input name="page" type="hidden" id="page" value="1" size="50">
      <input name="Submit" type="submit" class="btn_grey" value="查询"></td>
      </tr>
     </table>
     </form>
  </td>
     </tr>

 

      <tr>
        <td align="center" valign="top">
  <?php
  include("Conn/conn.php");
  $sql=mysql_query("select count(*) from tb_bookinfo b left join tb_bookcase c on b.bookcase=c.id join tb_booktype t on b.typeid=t.id");
        $perNumber=10; //每页显示的记录数
        $page=$_GET['page']; //获得当前的页面值
        $rs=mysql_fetch_array($sql);
        $totalNumber=$rs[0];
        $totalPage=ceil($totalNumber/$perNumber); //计算出总页数
        if (!isset($page)) { $page=1;} //如果没有值,则赋值1
        $startCount=($page-1)*$perNumber; //分页开始,根据此方法计算出开始的记录
   //读取指定记录数
  $query=mysql_query("select b.barcode,b.id as bookid,b.bookname,b.ISBN,b.inTime,t.typename,c.name from tb_bookinfo b left join tb_bookcase c on b.bookcase=c.id join tb_booktype t on b.typeid=t.id limit $startCount,$perNumber");
  $result=mysql_fetch_array($query);
        if($result==false){
  ?>
          <table width="100%" height="30"  border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td height="36" align="center">暂无图书信息!</td>
            </tr>
          </table>
          <table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
      <a href="book_add.php">添加图书信息</a> </td>
  </tr>
</table>
 <?php
}else{
?>
 <table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="87%">&nbsp;      </td>
 <td width="13%">
      <a href="book_add.php">添加图书信息</a></td>  
  </tr>
</table> 
  <table width="98%"  border="1" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF" bordercolordark="#D2E3E6" bordercolorlight="#FFFFFF">
  <tr align="center" bgcolor="#e3F4F7">
    <td width="13%">图书编号</td> 
    <td width="26%">图书名称</td>
    <td width="11%">图书类型</td>
    <td width="16%">出版社</td>
    <td width="10%">书架</td>
 <td width="12%">入库时间</td>
    <td width="6%">修改</td>
    <td width="5%">删除</td>
  </tr>
<?php
 if($_POST[key1]==""){
 do{
 ?>
  <tr>
    <td style="padding:5px;">&nbsp;<?php echo $result['barcode'];?></td> 
    <td style="padding:5px;"><a href="book_look.php?id=<?php echo $result['bookid'];?>"><?php echo $result['bookname'];?></a></td>
    <td style="padding:5px;">&nbsp;<?php echo $result['typename'];?></td> 
    <td style="padding:5px;">&nbsp;<?php echo $result['ISBN'];?></td> 
    <td style="padding:5px;">&nbsp;<?php echo $result['name'];?></td> 
 <td style="padding:5px;">&nbsp;<?php echo $result['inTime'];?></td>
    <td align="center"><a href="book_Modify.php?id=<?php echo $result['bookid'];?>">修改</a></td>
    <td align="center"><a href="book_del.php?id=<?php echo $result['bookid'];?>">删除</a></td>
  </tr>
<?
   }while($result=mysql_fetch_array($query));
}else{

     $f=$_POST[f];
     $key1=$_POST[key1];
     $sql=mysql_query("select count(*) from tb_bookinfo b left join tb_bookcase c on b.bookcase=c.id join tb_booktype t on b.typeid=t.id where $f like '%$key1%'");
     $perNumber=10; //每页显示的记录数
     $page=$_GET['page']; //获得当前的页面值
     $rs=mysql_fetch_array($sql);
     $totalNumber=$rs[0];
     $totalPage=ceil($totalNumber/$perNumber); //计算出总页数
    if (!isset($page)) { $page=1;} //如果没有值,则赋值1
      $startCount=($page-1)*$perNumber; //分页开始,根据此方法计算出开始的记录
   //读取指定记录数
   $query=mysql_query("select b.barcode,b.id as bookid,b.bookname,b.ISBN,b.inTime,t.typename,c.name from tb_bookinfo b left join tb_bookcase c on b.bookcase=c.id join tb_booktype t on b.typeid=t.id where $f like '%$key1%' limit $startCount,$perNumber"); //根据前面的计算出开始的记录和记录数  

$info=mysql_fetch_array($query);
if($info==true){
do{
?> 
 <tr>
    <td style="padding:5px;">&nbsp;<?php echo $info['barcode'];?></td> 
    <td style="padding:5px;"><a href="book_look.php?id=<?php echo $info['bookid'];?>"><?php echo $info['bookname'];?></a></td>
    <td style="padding:5px;">&nbsp;<?php echo $info['typename'];?></td> 
    <td style="padding:5px;">&nbsp;<?php echo $info['ISBN'];?></td> 
    <td style="padding:5px;">&nbsp;<?php echo $info['name'];?></td>
 <td style="padding:5px;">&nbsp;<?php echo $result['inTime'];?></td>
    <td align="center"><a href="book_Modify.php?id=<?php echo $info['bookid'];?>">修改</a></td>
    <td align="center"><a href="book_del.php?id=<?php echo $info['bookid'];?>">删除</a></td>
  </tr>
<?php
}while($info=mysql_fetch_array($query));
}else{
?>
    <table width="100%" height="30"  border="0" cellpadding="0" cellspacing="0">
       <tr>
         <td height="36" align="center">您检索的图书信息不存在,请重新检索!</td>
       </tr>
    </table>
<?php
}
}
}
?> 


<table width="98%"  border="0" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF" bordercolordark="#D2E3E6" bordercolorlight="#FFFFFF">
<tr>
  <td align="center">
 
  第<?php echo $page;?>页&nbsp;&nbsp;&nbsp;
  <a href="book.php?page=1&f=<?php echo $f;?>&key1=<?php echo $key1;?>">首页</a>
     <?
       if ($page != 1) {
     ?>
       <a href="book.php?page=<?php echo $page - 1;?>&f=<?php echo $f;?>&key1=<?php echo $key1;?>">上一页</a>
     <?php
     }
  /*
     for ($i=1;$i<=$totalPage;$i++) {
     ?>
     <a href="book.php?page=<?php echo $i;?>"><?php echo $i ;?></a>
     <?php
     }
  */
     if ($page<$totalPage) { //如果page小于总页数,显示下一页链接
     ?>
     <a href="book.php?page=<?php echo $page + 1;?>&f=<?php echo $f;?>&key1=<?php echo $key1;?>">下一页</a>
     <?php
       }
     ?> 
  <a href="book.php?page=<?php echo $totalPage;?>&f=<?php echo $f;?>&key1=<?php echo $key1;?>">尾页</a>
      &nbsp;&nbsp;&nbsp;共<?php echo $totalPage;?>页  
 
  </td>
</tr>
</table>
</td>
      </tr>
    </table>
</td>
  </tr>
</table><?php include("copyright.php");?></td>
  </tr>
</table>
</td>
  </tr>
</table>
</body>
</html>

原创粉丝点击