please help me in comment reply!

Started on the old forum in April 2012 · view the original in the archive · old links redirect here

7 replies · 841 views · started 14 years ago · 1 min read

2 participants
asifnayem Developer · 119 posts #1

i have a blog and i have a function to comment in my posts. now when i tried to reply of a comment, then my comment gone at the bottom of the comment. how to make it right after the comment on which i replied. my db is like this:

CREATE TABLE `comment` (
  `id` int(11) NOT NULL auto_increment,
  `bid` int(11) NOT NULL,
  `wid` int(11) NOT NULL,
  `uid` int(11) NOT NULL,
  `reply` int(11) NOT NULL,
  `comment` text NOT NULL,
  `time` int(11) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

where bid means the blogid, wid means the blog writer id, uid goes with the userid who comment reply is the parameter to collect on which the reply comment, comment is the comment, time is the time of the comment.

my php code is:

$qints = @mysql_query("select * from `comment` where bid = '$id'");
while ($commenting = mysql_fetch_array($qints)) {
$us = @mysql_fetch_array(mysql_query("select * from `user` where id='$commenting[3]'"));
$poster = htmlspecialchars_decode($us[4]);
$time = ts($commenting[6]);
echo "<ol class='commentlist'>";
echo "<li class='comment'>";
echo "<div id='comment'>";

echo "<div class='comm-top'>";//1
echo "<div class='comment-author vcard sleft'>";
echo "<img alt='$poster' src='$us[11]' class='avatar' height='40' width='40' />";
echo "<cite class='fn'><a rel='nofollow' style='color: #339966;' href='profile.php?id=$us[0]'>$poster</a></cite> <span class='says'>$sayslang</span>";
echo "</div>";

echo "<div class='comment-meta sright'>";
echo "<a href='#'>$time</a>";
echo "</div>";
echo "</div>";//1.

echo "<div class='comment-body'>";
echo "<p>".htmlspecialchars_decode($commenting[5])."</p>";
echo "<div class='reply'>";
echo "<a class='comment-reply-link' href='#rf=$commenting[0]'>$replylang</a>";
echo "</div>";
echo "</div>";

echo "<div class='comment-body-line'></div>";
echo "</div>";
echo "</li>";
echo "</ol>";
}

now can anyone please show me what to do?

asifnayem Developer · 119 posts #3

something else wrote: ORDER BY id

u misunderstood my post.. my problem is when i replied in a comment that means child comment, then the child comment was at the bottom of all comments. but i want the child comment right under neath of the main comment.

something else Fellow · 2,296 posts #4

you have 2 choices with ORDER ... ORDER BY id ASC (same as ORDER BY id) which is default or ORDER BY id DESC which is the way you dont want it?

Unless you mean sub commenting Eg:

this is some blog blah blah blah.

Peter comments: WOW reaally good.
sub reply

John comments: bad
sub reply
       sub comment ->    peter comments: @John: what do you mean bad? ->sub reply
       sub comment ->    John comments: @peter: it sucks ->sub reply

paul comments: blah
sub reply

Main Reply HERE
asifnayem Developer · 119 posts #5

yes i mean that sub commenting. when i commented of a comment, it goes at the end of all the comment. thats been my problem.

something else Fellow · 2,296 posts #6
REATE TABLE `comment` (
  `id` int(11) NOT NULL auto_increment,
  `bid` int(11) NOT NULL,
  `wid` int(11) NOT NULL,
  `uid` int(11) NOT NULL,
  `reply` int(11) NOT NULL,
  `comment` text NOT NULL,
  `time` int(11) NOT NULL,
  `subcomment` int(11) NOT NULL,
  `hasubcomment` int(1) DEFAULT 0,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

$qints = @mysql_query("select * from `comment` where bid = '$id'"); 
while ($commenting = mysql_fetch_array($qints)) { 
$us = @mysql_fetch_array(mysql_query("select * from `user` where id='$commenting[3]'")); 
$poster = htmlspecialchars_decode($us[4]); 
$time = ts($commenting[6]); 
echo "<ol class='commentlist'>"; 
echo "<li class='comment'>"; 
echo "<div id='comment'>"; 

echo "<div class='comm-top'>";//1 
echo "<div class='comment-author vcard sleft'>"; 
echo "<img alt='$poster' src='$us[11]' class='avatar' height='40' width='40' />"; 
echo "<cite class='fn'><a rel='nofollow' style='color: #339966;' href='profile.php?id=$us[0]'>$poster</a></cite> <span class='says'>$sayslang</span>"; 
echo "</div>"; 

echo "<div class='comment-meta sright'>"; 
echo "<a href='#'>$time</a>"; 
echo "</div>"; 
echo "</div>";//1. 
if($commenting['hassubcomment']==1)
{
$qintsx = @mysql_query("select * from `comment` where subcomment = '".$commenting['id']."'"); 
while ($commentingx = mysql_fetch_array($qintsx)) { 
$usx = @mysql_fetch_array(mysql_query("select * from `user` where id='$commenting[3]'")); 
$posterx = htmlspecialchars_decode($usx[4]); 
$timex = ts($commentingx[6]); 
echo "<ol class='commentlist'>"; 
echo "<li class='comment'>"; 
echo "<div id='comment'>"; 

echo "<div class='comm-top'>";//1 
echo "<div class='comment-author vcard sleft'>"; 
echo "<img alt='$posterx' src='$usx[11]' class='avatar' height='40' width='40' />"; 
echo "<cite class='fn'><a rel='nofollow' style='color: #339966;' href='profile.php?id=$usx[0]'>$posterx</a></cite> <span class='says'>$sayslang</span>"; 
echo "</div>"; 

echo "<div class='comment-meta sright'>"; 
echo "<a href='#'>$timex</a>"; 
echo "</div>"; 
echo "</div>";//1. 

echo "<div class='comment-body'>"; 
echo "<p>".htmlspecialchars_decode($commentingx[5])."</p>"; 
echo "<div class='reply'>"; 
echo "<a class='comment-reply-link' href='#rf=$commentingx[0]'>$replylang</a>"; 
echo "</div>"; 
echo "</div>"; 

echo "<div class='comment-body-line'></div>"; 
echo "</div>"; 
echo "</li>"; 
echo "</ol>";

}
echo "<div class='comment-body'>"; 
echo "<p>".htmlspecialchars_decode($commenting[5])."</p>"; 
echo "<div class='reply'>"; 
echo "<a class='comment-reply-link' href='#rf=$commenting[0]'>$replylang</a>"; 
echo "</div>"; 
echo "</div>"; 

echo "<div class='comment-body-line'></div>"; 
echo "</div>"; 
echo "</li>"; 
echo "</ol>"; 
} 

then when adding sub comment insert the id of the comment into subcomment and set hassubcomment to 1 (this is to prevent unnecessary calls to database)

asifnayem Developer · 119 posts #7

now i am using this:

$qints = @mysql_query("select * from `comment` where bid = '$id'");  
while ($commenting = mysql_fetch_array($qints)) {  
$us = @mysql_fetch_array(mysql_query("select * from `user` where id='$commenting[3]'"));  
$poster = htmlspecialchars_decode($us[4]);  
$time = ts($commenting[6]);  
echo "<ol class='commentlist'>";  
echo "<li class='comment'>";  
echo "<div id='comment'>";  

echo "<div class='comm-top'>";//1  
echo "<div class='comment-author vcard sleft'>";  
echo "<img alt='$poster' src='$us[11]' class='avatar' height='40' width='40' />";  
echo "<cite class='fn'><a rel='nofollow' style='color: #339966;' href='profile.php?id=$us[0]'>$poster</a></cite> <span class='says'>$sayslang</span>";  
echo "</div>";  

echo "<div class='comment-meta sright'>";  
echo "<a href='#'>$time</a>";  
echo "</div>";  
echo "</div>";//1.
echo "<div class='comment-body'>";  
echo "<p>".htmlspecialchars_decode($commenting[5])."</p>";  
echo "<div class='reply'>";  
echo "<a class='comment-reply-link' href='#rf=$commenting[0]'>$replylang</a>";  
echo "</div>";  
echo "</div>";  

echo "<div class='comment-body-line'></div>";  
echo "</div>";  
if($commenting[8]==1) 
{ 
$qintsx = @mysql_query("select * from `comment` where subcomment = '".$commenting['id']."'");  
while ($commentingx = mysql_fetch_array($qintsx)) {  
$usx = @mysql_fetch_array(mysql_query("select * from `user` where id='$commenting[3]'"));  
$posterx = htmlspecialchars_decode($usx[4]);  
$timex = ts($commentingx[6]);  
echo "<ul class='childen>";
echo "<li class='comment'>";  
echo "<div id='comment'>";
echo "<div class='comm-top'>";//1  
echo "<div class='comment-author vcard sleft'>"; 
echo "<img alt='$posterx' src='$usx[11]' class='avatar' height='40' width='40' />";  
echo "<cite class='fn'><a rel='nofollow' style='color: #339966;' href='profile.php?id=$usx[0]'>$posterx</a></cite> <span class='says'>$sayslang</span>";  
echo "</div>";
echo "<div class='comment-meta sright'>";  
echo "<a href='#'>$timex</a>";  
echo "</div>";  
echo "</div>";//1.  
echo "<div class='comment-body'>";  
echo "<p>".htmlspecialchars_decode($commentingx[5])."</p>";  
echo "<div class='reply'>";  
echo "<a class='comment-reply-link' href='#rf=$commentingx[0]'>$replylang</a>";  
echo "</div>";
echo "</div>";
echo "<div class='comment-body-line'></div>";
echo "</div>";
echo "</li>";
echo "</ul>";
}
}  
echo "</li>";  
echo "</ol>";  
} 

but seems its not showing the image of the sub comment, also showing the sub comment in the bottom of the all main comment.

something else Fellow · 2,296 posts #8

make sure you dont insert the bid but just the comment id into subcomment

As for the image ... it looks to be image of a user all i have done is copied your original querys and assigned them to a new variable name (same as other 1s just with x on the end) so i have no idea what $usx[11] is 😛

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close