Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Threaded comments pagination
    primarykey
    data
    text
    <p>I'm using the threaded comment from <a href="http://www.jongales.com/blog/2009/01/27/php-class-for-threaded-comments/" rel="nofollow">http://www.jongales.com/blog/2009/01/27/php-class-for-threaded-comments/</a> 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...</p> <p> <pre><code>public $parents = array(); public $children = array(); function __construct($comments) { foreach ($comments as $comment) { if ($comment['parent_id'] === NULL) { $this-&gt;parents[$comment['id']][] = $comment; } else { $this-&gt;children[$comment['parent_id']][] = $comment; } } } private function format_comment($comment, $depth) { If($depth == 0){ ?&gt; &lt;br /&gt;&lt;?php echo $comment['name']; ?&gt;&lt;br /&gt;&lt;?php echo $comment['datetime']; ?&gt;&lt;br /&gt;&lt;?php echo $comment['text']; ?&gt;&lt;/div&gt; &lt;a href="javascript:toggleDiv('&lt;?php echo $comment['id']; ?&gt;');"&gt;Raspunde&lt;/a&gt; &lt;div id="&lt;?php echo $comment['id']; ?&gt;" style="display: none;"&gt; The content in this div will hide and show (toggle) when the toggle is pressed. &lt;/div&gt; &lt;?php } If($depth &gt; 0){ ?&gt; &lt;div style="margin-left: 20px;"&gt; &lt;br /&gt;&lt;?php echo $comment['name']; ?&gt;&lt;br /&gt;&lt;?php echo $comment['datetime']; ?&gt;&lt;br /&gt;&lt;?php echo $comment['text']; ?&gt;&lt;/div&gt; &lt;/div&gt; &lt;?php } } private function print_parent($comment, $depth = 0) { foreach ($comment as $c) { $this-&gt;format_comment($c, $depth); if (isset($this-&gt;children[$c['id']])) { $this-&gt;print_parent($this-&gt;children[$c['id']], $depth + 1); } } } public function print_comments() { foreach ($this-&gt;parents as $c) { $this-&gt;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' =&gt; $id, 'parent_id' =&gt; $parent_id, 'name' =&gt; $name, 'text' =&gt; $text, 'datetime' =&gt; $datetime ); } $threaded_comments = new Threaded_comments($comments); $threaded_comments-&gt;print_comments(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload