Im having trouble with my Post and Comment to Post section of code. I am relatively new to coding and I am not even sure if this is even the best way to do this. The code will post, as well as comment correctly, but the problem is that it won’t display correctly. What happens is when it displays it will pull the blab in the correct order as well as the comments, but the comments repeat themselves on upon each post.
So for further clarification it looks like this…
- Post 1
- comment 1
- comment 2
-
comment 3
-
Post 2
- comment 1
- comment 2
- comment 3
-
comment 4
-
Post 3
- comment 1
- comment 2
- comment 3
- comment 4
- comment 5
The numbers stand for the ids
Here is my code.
// ------- MEMBER BLABS OUTPUT CONSTRUCTION ---------
$sql_blabs = mysql_query("SELECT id, mem_id, the_blab, blab_date, blab_type, device, fromid FROM blabbing WHERE mem_id='$id' ORDER BY blab_date DESC LIMIT 30");
while($row = mysql_fetch_array($sql_blabs)){
$blabid = $row["id"];
$fromid = $row["fromid"];
$blab_device = $row["device"];
$sql_comments = mysql_query("SELECT * FROM blab_comments WHERE blab_id='$blabid' ORDER BY id ASC");
$count_comment = mysql_num_rows($sql_comments);
if($count_comment > 0){
while($row2=mysql_fetch_array($sql_comments)){
$comment_mem_id = $row2['mem_id'];
$com_blab_id = $row2['blab_id'];
$comment_txt = $row2['the_comment'];
$comment_date = $row2['comment_date'];
$convertedTime = ($myObject -> convert_datetime($comment_date));
$whenComment = ($myObject -> makeAgo($convertedTime));
$sql_comment_user = mysql_query("SELECT firstname, lastname FROM myMembers WHERE id='$comment_mem_id' LIMIT 1");
while($row3 = mysql_fetch_array($sql_comment_user)){
$firstname = $row3['firstname'];
$lastname = $row3['lastname'];
$comment_user = $firstname.' '.$lastname;
}
$comment_pic = check_pic("members", $comment_mem_id, "40", "profile");
/////// Mechanism to Display Real Name Next to Username - real name(username) //////////////////////////
$DisplayCommentList .='
<div style="background-color:#e3eaf3; width:auto; height:auto; word-wrap: break-word;">
<div style="margin-right:10px; margin:8px; width:40px; height:40px; overflow:hidden; display:inline-block;">'.$comment_pic.'</div>
<div style="float:right; width:390px; margin-bottom:8px; margin-top:3px;">
<span class="liteGreyColor textsize9" style="width:auto;">'.$whenComment.'
<a href="profile.php?id=' . $fromid . '"><strong>'.$comment_user.'</strong></a> said via <em>'.$blab_device.'</em>
</span><br />'.$comment_txt.'<br />
</div>
</div>
<hr style="margin:0px; clear:both; margin-left:8px;" />';
}
}else{
$DisplayCommentList = "";
}
$uid = $row["mem_id"];
$the_blab = $row["the_blab"];
$the_blab = ($activeLinkObject -> makeActiveLink($the_blab));
$blab_date = $row["blab_date"];
$convertedTime = ($myObject -> convert_datetime($blab_date));
$whenBlab = ($myObject -> makeAgo($convertedTime));
$blab_date = $row["blab_date"];
$blab_type = $row["blab_type"];
$blab_pic = check_pic("members", $fromid, "60", "profile");
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$usersql = mysql_query("SELECT firstname, lastname FROM myMembers WHERE id='$fromid' LIMIT 1");
while($row = mysql_fetch_assoc($usersql)){
$fromuser = $row["firstname"];
$fromuserLast = $row["lastname"];
$fromusername = $fromuser . ' ' . $fromuserLast;
if(isset($_SESSION['idx'])){
$blabberDisplayList .= '
<table style="background-image:url(images/white_title.png); color:#333; border:#F0F0F0 1px solid; border-top: 0px; padding-bottom:10px;" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="18%" valign="top"><div id="blab_pic" style="overflow:hidden; width:60px; margin:10px 0px 10px 10px;">' . $blab_pic . '</div></td>
<td width="82%" valign="top" style="line-height:1.5em; padding-top:7px;">
<span id="myTable" class="liteGreyColor textsize9">' . $whenBlab . ' <a href="profile.php?id=' . $fromid . '"><strong>' . $fromusername . '</strong></a> said via <em>' . $blab_device . '</em></span><br />
' . $the_blab . '
</td>
</tr>
<tr>
<td width="18%" valign="top"></td>
<td width="82%" style="line-height:1.5em; padding-right:15px; background-color:#e3eaf3;" valign="top">
'.$DisplayCommentList.'
<div id="new_comment'.$blabid.'" style="display:none;">
</div>
<textarea id="Comment'.$blabid.'" style="width:99%; margin-top:8px; margin-left:8px;" rows="1"></textarea><br />
<input style="color:#666; float:right; background-color:transparent; border:0px; margin-left:8px; margin-right:8px;" type="submit" value="comment" onclick="javascript:SendComment(\''.$blabid.'\');" />
</td>
</tr></table>';
}}}
// ------- END MEMBER BLABS OUTPUT CONSTRUCTION ---------
The answer was to place the comment query into a function. While looping through the blabs, it would subsequently loop through “all” of the comments each time it passed over. I got it going now :). Thanks for the help!