http://www.jongales.com/blog/2009/01/27/php-class-for-threaded-comments/のスレッド化されたコメントを使用していますが、ページネーション システムを実装する方法がわかりません。解決策を探したが何も見つからなかったので、誰かが私に方向性や何かを教えてくれたら...
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();