我试图制作一条评论脚本,对评论做出回复并回复答复,这是我到目前为止所处的地方但如果不手动添加所有支票,我怎么能更深入?
目前看起来像这样:
Top Tier Comment #1
...Reply #1 To Top Tier Comment
......Reply #2 To Top Tier Comment
Top Tier Comment #2
...Reply To Top Tier Comment #2
......Reply to Reply on 1st Comment on #2 Top Tier Comment
这是我目前的代码:
$r_id = 102541;
$stmt = $mysqli->prepare("SELECT cid, comment, datetime, cid_parent, comments.uid, username, picture FROM comments JOIN members ON comments.uid = members.user_id WHERE rid = ?");
$stmt->bind_param('i', $r_id);
$stmt->execute();
$stmt->bind_result($cid, $comment, $datetime, $cidparent, $uid, $commentUsername, $commentPicture);
$stmt->store_result();
$totalComments=$stmt->num_rows;
while ($stmt->fetch()) {
if(empty($cidparent)) {
$topTierComments[$cid] = $comment;
} else {
$commentReplys[$cidparent][$cid] = $comment;
}
}
$indent = "...";
$indentTwo = "...";
foreach($topTierComments as $topTierCommentID => $topTierComment) {
echo $topTierComment."<br />";
if(isset($commentReplys[$topTierCommentID])){
foreach($commentReplys[$topTierCommentID] as $commentReplyID => $commentReply) {
echo $indent."".$commentReply."<br />";
if(isset($commentReplys[$commentReplyID])){
foreach($commentReplys[$commentReplyID] as $commentReplyID => $commentReply) {
$oldIndentTwo = $indentTwo;
$indentTwo .= "...";
echo $indentTwo."".$commentReply."<br />";
$indentTwo = $oldIndentTwo;
}
}
}
$indent .= "...";
}
$indent = "...";
}