Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8503685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:49:22+00:00 2026-06-11T01:49:22+00:00

I’m using the threaded comment from http://www.jongales.com/blog/2009/01/27/php-class-for-threaded-comments/ and I have no idea how to

  • 0

I’m using the threaded comment from http://www.jongales.com/blog/2009/01/27/php-class-for-threaded-comments/ and I have no idea how to implement a pagination system. If anybody could point me in a direction or something because I search for a solution but didn’t find anything…

public $parents  = array();
public $children = array();

function __construct($comments)
{
    foreach ($comments as $comment)
    {
        if ($comment['parent_id'] === NULL)
        {
            $this->parents[$comment['id']][] = $comment;
        }
        else
        {
            $this->children[$comment['parent_id']][] = $comment;
        }
    }
}

private function format_comment($comment, $depth)
{
     If($depth == 0){
        ?>
        <br /><?php echo $comment['name']; ?><br /><?php echo $comment['datetime']; ?><br /><?php echo $comment['text']; ?></div>
        <a href="javascript:toggleDiv('<?php echo $comment['id']; ?>');">Raspunde</a>
        <div id="<?php echo $comment['id']; ?>" style="display: none;">
        The content in this div will hide and show (toggle) when the toggle is pressed. 
        </div>
        <?php
     }

     If($depth > 0){
        ?>
        <div style="margin-left: 20px;">
        <br /><?php echo $comment['name']; ?><br /><?php echo $comment['datetime']; ?><br /><?php echo $comment['text']; ?></div>
        </div>
        <?php
     }   


}

private function print_parent($comment, $depth = 0)
{
    foreach ($comment as $c)
    {
        $this->format_comment($c, $depth);

        if (isset($this->children[$c['id']]))
        {
            $this->print_parent($this->children[$c['id']], $depth + 1);
        }
    }
}

public function print_comments()
{
    foreach ($this->parents as $c)
    {
        $this->print_parent($c);
    }
}}

$username = "Netra";
$SQL = "SELECT * FROM profile_comments WHERE name = '$username' ORDER BY datetime DESC";
$result = mysql_query($SQL) or die(mysql_error());

while($row = mysql_fetch_assoc($result)) {
    $id = $row['id'];
    $parent_id = $row['parent_id'];
    $name = $row['name'];
    $text = $row['text'];
    $datetime = $row['datetime'];

    $comments[] = array(
        'id' => $id,
        'parent_id' => $parent_id,
        'name' => $name,
        'text' => $text,
        'datetime' => $datetime
    );
}

    $threaded_comments = new Threaded_comments($comments);

    $threaded_comments->print_comments();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:49:23+00:00Added an answer on June 11, 2026 at 1:49 am

    Pagination simply will change two things in your queries. It will set the LIMIT and OFFSET different based on the current page. There are a few parts involved, mainly knowing the offset. This is easy, it is always the (PAGE_NUMBER * NUMBER_PER_PAGE) – NUMBER_PER_PAGE. You then dynamically change your sql based on the current page!

    It looks something like this:

    <?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;
        }
    
    
    }
    
    
    
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have thousands of HTML files to process using Groovy/Java and I need to
I have a view passing on information from a database: def serve_article(request, id): served_article
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a bunch of posts stored in text files formatted in yaml/textile (from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.