Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP/MySQL How to make my comments and replies display correctly?
    primarykey
    data
    text
    <p>I'm trying to display my comments and my comments replies on my web page but I can't get the replies to display with the correct comment can some one help correct this problem? </p> <p>And by the way all the <code>if else</code> statements are to display different colors for the commenter or replier if he or she is the page creator or user.</p> <p>Here is the MySQL tables.</p> <pre><code>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) ); </code></pre> <p>Here is the PHP &amp; MySQL code.</p> <pre><code>$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 &amp;&amp; $parent_id == 0){ echo '&lt;p class="page-creator-comment"&gt;' . $comments . '&lt;/p&gt;'; } else if($comment_user != $user_id &amp;&amp; $parent_id == 0) { echo '&lt;p class="commenter"&gt;' . $comments . ''; } else if($comment_user == $user_id &amp;&amp; $parent_id &gt;= 1){ echo '&lt;p class="page-creator-reply"&gt;' . $comments . '&lt;/p&gt;'; } else if($parent_id &gt;= 1){ echo '&lt;p class="reply"&gt;' . $comments . '&lt;/p&gt;'; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload