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

posted on 2018-05-17 11:34  PHP`reader  阅读(128)  评论(0编辑  收藏  举报