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

  • 相关阅读:
    CNN comprehension
    Gradient Descent
    Various Optimization Algorithms For Training Neural Network
    gerrit workflow
    jenkins job配置脚本化
    Jenkins pipeline jobs隐式传参
    make words counter for image with the help of paddlehub model
    make words counter for image with the help of paddlehub model
    git push and gerrit code review
    image similarity
  • 原文地址:https://www.cnblogs.com/index0629/p/9050168.html
Copyright © 2011-2022 走看看