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);
        }

  • 相关阅读:
    小村系列之十八:幸福的桥
    小村系列之十六:改革的石头
    获取<select>,<radio>,<checkbox>中未被选中的value值和被选中的value值
    display:inline-block,block,inline的区别与用法
    Java中List Set Map集合的遍历
    C#自定义List类
    C#获取文件和文件夹大小
    C# winform带进度条的图片下载
    C#委托的详细使用
    asp.net cookie和session的详细使用
  • 原文地址:https://www.cnblogs.com/index0629/p/9050168.html
Copyright © 2011-2022 走看看