加入收藏 | 设为首页 | 会员中心 | 我要投稿 源码门户网 (https://www.92codes.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php分页功能怎么做?详解php封装完成实例

发布时间:2021-12-30 22:51:13 所属栏目:PHP教程 来源:互联网
导读:我们在做开发的时候,如果数据太多就会使用分页功能。下面小编就给大家分享一个使用php封装实现的page分页类,感兴趣的朋友可以了解一下,下面是实现效果。 效果图 1.测试实例test.php ?php header(Content-Type: text/html; charset=utf-8); date_default
    我们在做开发的时候,如果数据太多就会使用分页功能。下面小编就给大家分享一个使用php封装实现的page分页类,感兴趣的朋友可以了解一下,下面是实现效果。
 
       效果图
 
 
 
       1.测试实例test.php
 
<?php
header("Content-Type: text/html; charset=utf-8");
date_default_timezone_set("Asia/Shanghai"); //时区
 
require_once('page.class.php');
 
$showrow = 5;
$curpage = empty($_GET['page']) ? 1 : $_GET['page'];
$url = "?page={page}";
$dsn = 'mysql:host=xxx.xxx.80.xxx;dbname=admin';
$pdo = new PDO($dsn, 'root', 'root');
$pdo->query('set names utf8');
$sql = "SELECT * from operator_list where 1=1";
 
$res_gg = $pdo->query("SELECT count(*) as ctn from operator_list where 1=1;");
$result = $res_gg->fetch();
 
$total = $result["ctn"];
 
if (!empty($_GET['page']) && $total != 0 && $curpage > ceil($total / $showrow)) {
 $curpage = ceil($total_rows / $showrow);
}
$sql .= " LIMIT " . ($curpage - 1) * $showrow . ",$showrow;";
 
$res_zz = $pdo->query($sql);
$result = $res_zz->fetchAll();
 
//print_r(json_encode($result));die;
 
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 <title></title>
 <meta name="keywords" content="入库"/>
 <meta name="description" content="入库"/>
 <script type="text/javascript" src="static/js/jquery-1.11.0.min.js?v=1"></script>
 <link rel="stylesheet" type="text/css" href="static/css/common.css" rel="external nofollow" />
</head>
<body>
<div class="head">
 <!-- <div class="head_inner clearfix">-->
 <!--  <ul id="nav">-->
 <!--   <li><a href="javascript;" rel="external nofollow" rel="external nofollow" >商品列表</a></li>-->
 <!--   <li><a href="javascript;" rel="external nofollow" rel="external nofollow" >详情列表</a></li>-->
 <!--  </ul>-->
 <!--    <a class="logo" href="javascript" rel="external nofollow" >
      <img src="javascript;" alt="公司logo" /></a> -->
 <!-- </div>-->
</div>
<div class="container">
 <div class="demo">
  <h2 class="title">报表</h2>
 
  <div class="showData">
   <table width="100%" border="0" align="center"
   style="border:1px solid #ccc;" cellpadding="0" cellspacing="1">
    <tr align="center">
     <td>ID</td>
     <td>商品编号</td>
     <td>订阅状态</td>
     <td>商品状态</td>
     <td>修改时间</td>
     <td>创建时间</td>
    </tr>
    <?php
    if (!empty($result)) {
     foreach ($result as $k => $v) {
      ?>
      <tr align="center">
       <td><?php echo $v['id']; ?></td>
       <td><?php echo $v["customer_id"]; ?></td>
       <td><?php echo $v["name"]; ?></td>
       <td><?php echo $v["role_id"]; ?></td>
       <td><?php echo $v["status"]; ?></td>
       <td><?php echo $v["cdate"]; ?></td>
      </tr>
      <?php

(编辑:源码门户网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读