Benim yorum ve yanıtlarını göstermek için ama nedense ben sadece ana görüş ve değil yanıtlarını görüntüleyebilir, ben onu aramak ne olduğunu düşünüyorum bir fonksiyon kullanıyorum. Birisi bana bu sorunu çözmek yardımcı olabilir?
İşte benim Çıktı ŞİMDİ.
PARENT COMMENT 1
PARENT COMMENT 2
PARENT COMMENT 3
İşte benim İSTENİLEN çıktı.
PARENT COMMENT 1
child comment 1
child comment 2
PARENT COMMENT 2
child comment 1
child comment 2
child comment 3
child comment 4
PARENT COMMENT 3
İşte MySQL yorumlar tablodur.
CREATE TABLE articles_comments (
comment_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
parent_comment_id INT UNSIGNED NOT NULL,
user_id INT UNSIGNED NOT NULL,
article_id INT UNSIGNED NOT NULL,
comment TEXT NOT NULL,
date_created DATETIME NOT NULL,
PRIMARY KEY (comment_id),
);
İşte benim PHP & olduğunu MySQL kodu.
function make_comments($parent_comment_id = 0, $comment_id = 0) {
global $user_id;
foreach ($parent_comment_id as $id => $comment) {
if($comment['user_id'] == $user_id && $comment['parent_comment_id'] == 0){
echo '<div style="color: orange;">' . $comment['comment'] . '</div><br /><br />';
if($comment_id == $comment['parent_comment_id']){ //display replies
if($comment['user_id'] == $user_id && $comment['parent_comment_id'] >= 1) {
echo '<div style="color: purple;">' . $comment['comment'] . '</div><br /><br />';
} else if($comment['parent_comment_id'] >= 1) {
echo '<div style="color: blue;">' . $comment['comment'] . '</div><br /><br />';
}
}
} else if($comment['user_id'] != $user_id && $comment['parent_comment_id'] == 0) {
echo '<div style="color: brown;">' . $comment['comment'] . '</div><br /><br />';
if($comment_id == $comment['parent_comment_id']){ //display replies
if($comment['user_id'] == $user_id && $comment['parent_comment_id'] >= 1) {
echo '<div style="color: purple;">' . $comment['comment'] . '</div><br /><br />';
} else if($comment['parent_comment_id'] >= 1) {
echo '<div style="color: blue;">' . $comment['comment'] . '</div><br /><br />';
}
}
}
}
}
$dbc = mysqli_query($mysqli, "SELECT articles_comments.comment_id, articles_comments.parent_comment_id, articles_comments.comment, articles_comments.user_id FROM articles_comments LEFT JOIN users ON articles_comments.user_id = users.user_id WHERE article_id = '" . $article_id . "' ORDER BY parent_comment_id ASC");
if (!$dbc) {
print mysqli_error();
}
$comment_order = array();
while (list($comment_id, $parent_comment_id, $comment_text, $comment_user, $comment_id) = mysqli_fetch_array($dbc)) {
$comment_order[$parent_comment_id][$comment_id] = array('parent_comment_id' => $parent_comment_id, 'comment_id' => $comment_id, 'comment' => $comment_text, 'user_id' => $comment_user, 'comment_id' => $comment_id);
}
make_comments($comment_order[0], $comment_id);