zoukankan      html  css  js  c++  java
  • PHP 分页

    <ul>
        <?php $c =new conn11('localhost','user','','test');
            $c->connect();//连接数据库

            $sql2 = 'select count(*) from liuyan';
            $res3 =$c->sel($sql2);
            $res4 = $c->fetch($res3);
            $now = 0;//当前显示第几页
            $show =3;//一页显示几条
            $sum = $res4['count(*)'];//总条数
            $max = floor($sum/$show);//向下去整


            if(isset($_GET['a'])){
                $now = $_GET['a'];
            }//判断是否有GET传值 是否点击了下一页
             $total =$now*$show;
            $sql = "select text from liuyan limit {$total},{$show}";
            $res = $c->sel($sql);
           while ($res2 = $c->fetch($res)){//遍历数据库
             ?>
               <li><?php echo $res2['text']?></li>
            <?php
           }
        ?>

    <?php
        if($now>0){
        ?>
            <a href="fenye.php?a=<?php echo $now-1 ?>">上一页</a>
        <?php
        }
    ?>
    <?php
    if($now<$max){
        ?>
        <a href="fenye.php?a=<?php echo $now+1 ?>">下一页</a>
        <?php
    }
    ?>
    </ul>
     
     
     
     
     
    ------------------------------------------conn配置---------------------------------------------------------
     
     
     
     

    class conn11
    {
        var $host = '';
        var $user = '';
        var $pass = '';
        var  $db   = '';
        var  $point= '';
    //构造方法
       function __construct($host,$user,$pass,$db,$point="3306")
       {
            $this->host=$host;
           $this->user=$user;
           $this->pass=$pass;
           $this->db=$db;
           $this->point=$point;
       }
       function  con(){
           $connect = mysqli_connect($this->host,$this->user,$this->pass,$this->db,$this->point);
           return $connect;
       }

      //连接数据库
        function connect(){

            if(mysqli_query($this->con(),"set names utf8")){
                return true;
            }
            else{
                return false;
            }
        }
        //执行SQL语句
        function sel ($sql){

             $res =  mysqli_query($this->con(),$sql);
            return $res;
        }

        //遍历
        function fetch($a){
           return mysqli_fetch_assoc($a);
        }

  • 相关阅读:
    C# 泛型的逆变与协变
    C# 元组
    DNS服务原理与搭建自己的DNS服务器
    浅析DNS域名解析过程
    Python turtle.circle()函数
    Python 实现点名系统
    PyCharm Debugger中Step Over、Step Into、Step Into My Code、Force Step Into、Step Out、Run to Cursor意思区别
    TypeScript与JavaScript比较(区别)
    微信小程序开发环境搭建
    Windows.edb 文件占据巨大的硬盘存储空间
  • 原文地址:https://www.cnblogs.com/index0629/p/9050168.html
Copyright © 2011-2022 走看看