PHP / MySQL nasıl benim yorum yapmak ve cevaplar doğru gösterilecek?

0 Cevap php

Benim web sayfasında benim yorum ve benim yorum yanıtları görüntülemek çalışıyorum ama bazı biri bu sorunu gidermek yardımcı olabilir ben cevaplar doğru yorum ile göstermek için alamıyorum?

Ve arada tüm if else ifadeleri o sayfa yaratıcısı veya kullanıcı ise yorumcu veya replier farklı renkleri göstermek için vardır.

Burada MySQL tablo olduğunu.

CREATE TABLE comments (
comment_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
parent_id INT UNSIGNED NOT NULL,
user_id INT UNSIGNED NOT NULL,
page_id INT UNSIGNED NOT NULL,
comment TEXT NOT NULL,
date_created DATETIME NOT NULL,
PRIMARY KEY (id),
KEY user_id (user_id),
KEY page_id (page_id)
);


CREATE TABLE users (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
user_id INT UNSIGNED NOT NULL, 
PRIMARY KEY (id)
);

Burada PHP & olduğunu MySQL kodu.

$mysqli = mysqli_connect("localhost", "root", "", "sitename");
$dbc = mysqli_query($mysqli,"SELECT comments.*, users.*
                             FROM comments
                             LEFT JOIN users 
                             ON comments.user_id = users.user_id
                             WHERE page_id = $page_id
                             ORDER BY parent_id ASC");

if (!$dbc) {
    print mysqli_error();
}  else {
    while($row = mysqli_fetch_array($dbc)){
        $comment_user = $row['user_id'];
        $comment_id = $row['comment_id'];
        $comments = $row['comment'];
        $parent_id = $row['parent_id'];

            if($comment_user == $user_id && $parent_id == 0){

                echo '<p class="page-creator-comment">' . $comments . '</p>';

            } else if($comment_user != $user_id && $parent_id == 0) {

                echo '<p class="commenter">' . $comments . '';

            } else if($comment_user == $user_id && $parent_id >= 1){

                echo '<p class="page-creator-reply">' . $comments . '</p>';

            } else if($parent_id >= 1){

                echo '<p class="reply">' . $comments . '</p>';

            }
    }
}

0 Cevap