php分页显示双表查询的内容

来源:互联网 发布:相册制作软件哪个好 编辑:程序博客网 时间:2024/06/06 04:50
代码部分:
<?php
header("Content-type: text/html; charset=utf-8");
error_reporting(0);
error_reporting(E_ALL ^ E_DEPRECATED);
/**1 传入页码**/
if(empty($_GET['p'])||$_GET['p']<0){
                       $page=1;
                      }else {
                     $page=$_GET['p'];
                     }
                     //$page=$_GET['p'];
/**2 根据页码取出数据 :php->mysql处理**/
$host = "";
$username = "";
$password = "";
$db="";
$pageSize=10;
$showPage=5;
//链接数据库
$conn = mysql_connect($host,$username,$password);
if(!$conn){
  echo "链接数据库失败";
  exit;
}
//选择所要操作的数据库
mysql_select_db($db);
//设置数据库编码格式
mysql_query("SET NAMES UTF8");
//编写sql获取分页SELECT*FROM表名LIMIT起始位置,显示条数
$sql = "SELECT*FROM bill order by BillID desc LIMIT ".($page-1)*$pageSize .",$pageSize";
// //把sql语句传送数据中
$result= mysql_query($sql);
$sql1="SELECT * FROM bill,user WHERE bill.UserID=user.UserID";
$result1= mysql_query($sql1);
$k=0;
$UserName=array();
while($row1 = mysql_fetch_array($result1)){
  $UserName[$k]=$row1['UserName'];
  $k++;
}
?>
<html>
<head>
  <link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
  <link rel="stylesheet" href="css/mypage.css">
   <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
   <script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>

</head>
<style>
html{background-color:#E3E3E3;}
.tabindex{

  margin-left: 200px; margin-top: 50px;text-align: center;font-size: 18px;
}
</style>
<body style="text-align:cencer">
<div id="tabCot_product_1" class="tabCot" text-align:"center"  >
  <table class="table table-hover"style="">
                            <caption >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</caption>
                           <caption class="lead" style="font-size:26px">会费记录表</caption>
                           <caption >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</caption>
                               <thead>
                               <tr>
                               <th>收支ID</th>
                               <th>管理员</th>
                               <th>收支时间</th>
                               <th>操作时间</th>
                               <th>收支总数</th>
                               <th>收支类型</th>
                               <th>交易内容</th>
                               <th>交易人</th>
                               <th>剩余金额</th>
                               <th>修改</th>
                               <th>删除</th>
                               </tr>
                               </thead>
                    <tbody>
                      <?php
                while($row = mysql_fetch_array($result)){        
                 echo "<tr>";
                
                echo "<td  >{$row['BillID']}</td>";
                echo "<td  >{$UserName[--$k]}</td>";
                echo "<td  >{$row['ChangeTime']}</td>";
                echo "<td  >{$row['OperateTime']}</td>";
                echo "<td  >{$row['Sum']}</td>";
                echo "<td  >{$row['DealType']}</td>";
                echo "<td  >{$row['DealDescription']}</td>";
                echo "<td  >{$row['Contener']}</td>";
                echo "<td  >{$row['Remainer']}</td>";

                echo "<td  >
          <a href='change.php?id=".$row['BillID']."''><img src='images/change.png'></img> </a>
             </td>";
                echo "<td  >
        <a href='delhuifei.php?id=".$row['BillID']."''><img src='images/del.png'></img></a>
            </td>";
            echo "</tr>";
                 }
                 mysql_free_result($result);
               ?> 
             </tbody>
         </table>
       </div>
         <div class="mypage">
<?php 
$total_sql="SELECT COUNT(*)FROM bill";
$total_result=mysql_fetch_array(mysql_query($total_sql));
$total=$total_result[0];
//计算页数
$total_pages =ceil($total/$pageSize);
mysql_close($conn);
/**3显示数据+分页条**/
$page_banner="<div class ='pageview'>";
//计算偏移量
$pageoffset=($showPage-1)/2;
$page_banner="<div class='pageview' >";
if($page > 1){
  
   $page_banner.="<a href='".$_SERVER['PHP_SELF']."?p= 1 '' class='prev-link link' >首页</a>";
   $page_banner.="<a href='".$_SERVER['PHP_SELF']."?p=".($page-1)."' class='prev-link link'><上一页</a>";
}
else{
   
     $page_banner.="<span class='prev-link link'> <a>首页</a></span>";
     $page_banner.="<span class='prev-link link'> <a><上一页</a></span>";

}
//初始化数据
$start=1;
$end = $total_pages;

/* $page_banner="<div class='pageview'>";
 */
if($total_pages >$showPage) {
if($page >$pageoffset+1){
  
    $page_banner.="...";

}
if($page > $pageoffset){
  
  $start =$page - $pageoffset;
    $end=$total_pages > $page+$pageoffset ? $page+$pageoffset :$total_pages;
}
else{
   $start=1;
   $end=$total_pages > $showPage ? $showPage : $total_pages;

}
if($page + $pageoffset > $total_pages){
   $start=$start-($page+$pageoffset-$end);
   
}

for($i=$start;$i<=$end;$i++){
  if($page==$i){
    
    $page_banner.="<span class ='link'>$i</span>";
  }else{
    
$page_banner.="<a href='".$_SERVER['PHP_SELF']."?p=".$i."' class='link'>$i</a>";
}
}
if($total_pages>$showPage&&$total_pages>$page+$pageoffset){
  
   $page_banner.="...";

}
if($page <$total_pages){
  
$page_banner.="<a href='".$_SERVER['PHP_SELF']."?p=".($page+1)."' class='link next'>下一页></a>";
$page_banner.="<a href='".$_SERVER['PHP_SELF']."?p=".($total_pages)."' class='link next'>尾页</a>";
}
else{
  
   $page_banner.="<span class ='disable'> <a>尾页</a></span>";
     $page_banner.="<span class ='link next'> <a>下一页></a></span>";

}
$page_banner.="共{$total_pages}页";
 $page_banner.="<form action ='mypage.php method='get'>";
// $page_banner.="到第<input type ='text' size='2' name='p'>页";
// $page_banner.="<input type='submit' value='确定'>";
 $page_banner.="</form></div>";
echo $page_banner;
?>
         
 </div>
<body>
  </html>
css:




/* 分页*/
.pageview{width:550px; margin: 50px auto; margin-right:420px;}
.pageview {padding: 12px 0;text-align: right;line-height: 26px;}
.pageview a{text-decoration: none;}
.pageview .link {display: inline-block;padding: 0 10px;color: #fff;background-color: #7eade5;border-radius: 3px;height: 27px;margin: 0 0 2px 3px;border: 0;cursor: pointer}
.pageview .hover,.pageview a.link:hover {background-color: #0b64b6;  }
.pageview .nub input {width: 55px;text-align: center;font: 700 12px/25px Arial;border: 1px solid #ddd;background-color: #fff; margin: 0 5px;}
.bigtit,.bigtit .h2,.rastbox .h2 { line-height: 40px  }
.pageview span.link { background-color: #ddd;  cursor: not-allowed}
0 0
原创粉丝点击