PHP function problem?

nitro

New Member
I'm using a function I think that is what you call it, to display my comments and their replies but for some reason I can only display the parent comments and not their replies. can someone help me fix this problem?Here is my Output NOW.\[code\]PARENT COMMENT 1PARENT COMMENT 2PARENT COMMENT 3\[/code\]Here is my DESIRED output.\[code\]PARENT COMMENT 1 child comment 1 child comment 2PARENT COMMENT 2 child comment 1 child comment 2 child comment 3 child comment 4PARENT COMMENT 3\[/code\]Here is MySQL comments table.\[code\]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),);\[/code\]Here is my PHP & MySQL code.\[code\]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);\[/code\]
 
Back
Top