PHP multi-post issue.
- by user1887185
When I have two or more comments on a post, it show the post again and the next comment underneath it. How do I make it so it shows only the post once and the comments underneath it if there are multiple comments?
$sql_posts = mysql_query("SELECT * FROM posts ORDER BY post_date DESC ");
$postDisplayList = "";
while($row = mysql_fetch_array($sql_posts)){
$postid = $row["id"];
$uid = $row["user_id"];
$the_post = $row["post"];
$post_date = $row["post_date"];
$sql_mem_data = mysql_query("SELECT id, username, firstname, lastname FROM users WHERE id='$uid' LIMIT 1");
while($row = mysql_fetch_array($sql_mem_data)){
$uid = $row["id"];
$username = $row["username"];
$firstname = $row["firstname"];
$lastname = $row["lastname"];
}
$sql_com_data = mysql_query("SELECT * FROM comments WHERE post_id='$postid' ");
while($row = mysql_fetch_assoc($sql_com_data)){
$uid1 = $row["user_id"];
$comment = $row["comment"];
$whencomment = $row["comment_date"];
$sql_com_data_user = mysql_query("SELECT * FROM users WHERE id='$uid1' ");
while($row = mysql_fetch_array($sql_com_data_user)){
$username1 = $row["username"];
$firstname1 = $row["firstname"];
$lastname1 = $row["lastname"];
}
$postDisplayList .= '
<table width="100%" align="center" cellpadding="6" style="background-color:#F2F2F2; ">
<tr>
<td width="93%" bgcolor="#F2F2F2" style="line-height:1.5em;" valign="top">
<span class="liteGreyColor textsize9"> ' . $post_date . ' <a href="profile.php?id=' . $uid . '"><strong>' . $username . '</strong></a></span><br />
<span class="textsize14"> ' . $the_post . '</span>
</td>
</tr>
<tr>
<td width="93%" bgcolor="#F2F2F2" style="line-height:1.5em;" valign="top">
<span class="liteGreyColor textsize9"> ' . $whencomment . ' <a href="profile.php?id=' . $uid1 . '"><strong>' . $username1 . '</strong></a></span><br />
<span class="textsize14"> ' . $comment . '</span>
</td>
</tr>
</table>';