PHP线程化注释分页

PHP线程化注释分页,php,mysql,threaded-comments,Php,Mysql,Threaded Comments,我使用的是来自的线程注释,我不知道如何实现分页系统。如果有人能给我指个方向什么的,因为我在寻找解决方案,但什么都没找到 public$parents=array(); public$children=array(); 函数构造($comments) { foreach($comments作为$comment) { if($comment['parent_id']==NULL) { $this->parents[$comment['id']][]=$comment; } 其他的 { $this-

我使用的是来自的线程注释,我不知道如何实现分页系统。如果有人能给我指个方向什么的,因为我在寻找解决方案,但什么都没找到

public$parents=array();
public$children=array();
函数构造($comments)
{
foreach($comments作为$comment)
{
if($comment['parent_id']==NULL)
{
$this->parents[$comment['id']][]=$comment;
}
其他的
{
$this->children[$comment['parent_id']][]=$comment;
}
}
}
私有函数格式\注释($comment,$depth)
{
如果($depth==0){
?>






分页只会改变查询中的两件事。它会根据当前页面设置不同的限制和偏移量。这涉及到几个部分,主要是知道偏移量。这很简单,始终是(页码*页码)-页码。然后根据当前页面动态更改sql

它看起来像这样:

<?php 

class Pagination{

    public $total_results;
    public $total_pages;
    public $per_page;
    public $offset;
    public $page;

    public function __construct($per_page=20, $total_results=0, $page=1){
        $this->per_page = $per_page;
        $this->total_results = $total_results;
        $this->page = $page;
        $this->set_total_pages();
        $this->set_offset();
        $this->prepare_displays();
    }

    public function set_total_pages(){
        $this->total_pages = ceil($this->total_results / $this->per_page);
    }

    public function set_offset(){
        $this->offset = ($this->page * $this->per_page) - $this->per_page;
    }

    public function has_next_page(){
        if($this->page < $this->total_pages){
            return true;
        }else{
            return false;
        }
    }

    public function has_previous_page(){
        if($this->total_pages > 1 && $this->page > 1){
            return true;
        }else{
            return false;
        }
    }


    public function check_page_exists(){
        return (($this->total_pages > 0) && ($this->page > $this->total_pages)) || $this->page < 1 ? false : true;
    }


}




?>

<?php 

class Pagination{

    public $total_results;
    public $total_pages;
    public $per_page;
    public $offset;
    public $page;

    public function __construct($per_page=20, $total_results=0, $page=1){
        $this->per_page = $per_page;
        $this->total_results = $total_results;
        $this->page = $page;
        $this->set_total_pages();
        $this->set_offset();
        $this->prepare_displays();
    }

    public function set_total_pages(){
        $this->total_pages = ceil($this->total_results / $this->per_page);
    }

    public function set_offset(){
        $this->offset = ($this->page * $this->per_page) - $this->per_page;
    }

    public function has_next_page(){
        if($this->page < $this->total_pages){
            return true;
        }else{
            return false;
        }
    }

    public function has_previous_page(){
        if($this->total_pages > 1 && $this->page > 1){
            return true;
        }else{
            return false;
        }
    }


    public function check_page_exists(){
        return (($this->total_pages > 0) && ($this->page > $this->total_pages)) || $this->page < 1 ? false : true;
    }


}




?>