PDA

View Full Version : While loop through comments



jnscollier
05-20-2007, 07:07 PM
I have a while loop that loops through the comments for a particular blog and displays them. Everything works great there, and it shows every comment related to the blog.

I want users to be able to reply to comments posted, so I have this form that pops up (using javascript) with a text box when someone clicks "reply" under the comment. I just added this Reply link and what happens is that when the link is clicked it only shows the reply box under the first comment, no matter what reply link was clicked (for ex: if it was clicked on the tenth comment, it'll still show under the first comment as a reply to the first comment. If I remove the reply link and just display the reply boxes, they all show up with the right commentid under the appropriate comment. It's just when I have the link that causes the problem.

How can I get the reply link to pull up the reply box under the appropriate comment and associated to the appropriate commentid?

Hope this makes sense, any help would be appreciated!

thetestingsite
05-20-2007, 07:13 PM
Can you post either a link to the page you want this done on or at least the source code? This will help us out a lot.

jnscollier
05-20-2007, 07:18 PM
Ok i think i took off all the validation....

here's the link
(link removed)
Thanks!!

jnscollier
05-20-2007, 07:21 PM
Oh yeah, the reply itself is not functioning yet... I'm just trying to get the form positioned correctly first... I don't know if that matters.

thetestingsite
05-20-2007, 07:28 PM
You are calling the showForm function with the same id for every link. In other words, you are showing it like so:



<a href="#" onclick="showForm('theForm2'); return false;">Reply</a>


for every "Reply" link. What you could do (in the while loop of the PHP code) is assign a value for each comment (1,2,3...) by simply using the "id" or "count" of the comment. This goes for the div id as well.

Hope this helps and makes sense.

jnscollier
05-20-2007, 07:34 PM
Each comment currently is associated with a commentid... is that what you're talking about? I guess my question is... do i need to add something to the reply link to make it work properly?


$cmtqry="select * from ".BLOG_COMMENTS." where eparent='".$HTTP_GET_VARS['blogid']."' order by commentId ASC Limit $start , $rows_per_page";
$cmtres=mysql_query($cmtqry);
$cmtrows=mysql_num_rows($cmtres);
if($cmtrows > 0){
while($cmtarr=mysql_fetch_array($cmtres)){

thetestingsite
05-20-2007, 07:39 PM
Yes, for your while loop (where you display the comments and create the link and form) you will need to do something like this:



<a class="privacylink" href="#" onclick="showForm('<?php echo $commentID;?>'); return false;">Reply</a> &nbsp;&nbsp;

<div id="<?php echo $commentID;?>" style="display: none;">

<form action="replycomments.php" name="<?php echo $commentID;?>" method="post" onSubmit="return checkfields()">
<br><textarea cols= "49" rows= "3" name= "replycomment"></textarea><br>
<input type ="text" value="<?php echo $commentID;?>" name="commentid">
<input type = "hidden" name= "blogid" value= "220">
<input onClick="validate();" type="button" value="Reply" name="cmdSubmit"><input type="submit" onclick="hideForm('<?php echo $commentID;?>'); return false;" value="Nevermind">
</form>

</div>


Hope this helps.

jnscollier
05-20-2007, 07:43 PM
Has anyone ever told you how awesome you are???? That worked, THANK YOU SOOOO MUCH!!!!!

jnscollier
05-20-2007, 11:20 PM
So yeah, I thought that once I got the reply layout fixed (which testingsite helped me with - thanks again btw!) all my worries were over... Nope!

I thought i would just need to make an action page and everything would work perfectly... but life isn't that easy. I'm sure I'm missing smthg so friggin obvious, but I can't figure this out and I've been working on trying to figure this out for hours now!!!

Here's the link again:

(link removed)

When user hits reply to a certain comment, the comment box pops up, it's all great and dandy. EXCEPT, it will not submit (when you hit reply, nothing happens). I have an action page and everything... I don't know what the heck i'm doing wrong. I looked in IE and it says object required and I can't figure out what i'm missing. I've removed all validation and everything, any help would be appreciated you guys!

thetestingsite
05-21-2007, 02:34 AM
You have the button that closes the reply box as the submit button, instead of the otherway around. This should fix your problem.