PHP error question

haritsu

New Member
I keep getting the following error below. How can I correct this error?\[code\]Warning: Invalid argument supplied for foreach() on line 25.\[/code\]Line 25 is.\[code\]foreach ($parent_comment_id as $id => $comment) {\[/code\]Here is the PHP & MySQL code.\[code\]function make_comments($parent_comment_id = 0, $comment_id = 0) {global $user_id;global $comment_order;foreach ($parent_comment_id as $id => $comment) { if($comment['user_id'] == $user_id && $comment['parent_comment_id'] == 0){ $comment_id = $comment['comment_id']; echo '<div>' . $comment['comment'] . '</div>'; if($comment_id == $comment['parent_comment_id']){ if($comment['user_id'] == $user_id && $comment['parent_comment_id'] >= 1) { $comment_id = $comment['comment_id']; echo '<div>' . $comment['comment'] . '</div>'; } else if($comment['parent_comment_id'] >= 1) { $comment_id = $comment['comment_id']; echo '<div>' . $comment['comment'] . '</div>'; } } } else if($comment['user_id'] != $user_id && $comment['parent_comment_id'] == 0) { $comment_id = $comment['comment_id']; echo '<div>' . $comment['comment'] . '</div>'; if($comment_id == $comment['parent_comment_id']){ if($comment['user_id'] == $user_id && $comment['parent_comment_id'] >= 1) { $comment_id = $comment['comment_id']; echo '<div>' . $comment['comment'] . '</div>'; } else if($comment['parent_comment_id'] >= 1) { $comment_id = $comment['comment_id']; echo '<div>' . $comment['comment'] . '</div>'; } } } make_comments($comment_order[$id]); }}$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 articles_comments.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