Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8883099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:44:02+00:00 2026-06-14T20:44:02+00:00

I have a comment and reply section in a website I’m building. The reply

  • 0

I have a comment and reply section in a website I’m building. The reply section is set to shift right with a margin-left 10%. But when I test the code it’s shifting each reply to the right rather than all the replies shifting together. I’m stuck because the replies are looping inside the comments and I don’t know how to fix it. Here is the code…

        // Comments section
        // Get Username and ID from database
        if ($login->isLoggedIn()) {
            $userquery = "SELECT * FROM settings WHERE user_id=$userid";
            $usersql = mysql_query($userquery) or die('SQL Error :: '.mysql_error());
            $userqueryrow = mysql_fetch_assoc($usersql);
            $usercommentname = $userqueryrow['display_name'];
            } else {
            }

        // Posted Comments 
        $commentquery = "SELECT * FROM comments WHERE listing_id=$listingid AND response_to_id='0' ORDER BY comment_ts ASC";
        $commentsql = mysql_query($commentquery) or die('SQL Error :: '.mysql_error());

         if(mysql_num_rows($commentsql) == 0){ 
            echo '<div align="center">No comments have been posted yet.</div>';                        
                } else {    
            while($commentrow=mysql_fetch_array($commentsql))
            {
            // Get comment display name from database
            // Get Username and ID from database
            $commentid = $commentrow['comment_id'];
            $commenterid = $commentrow['user_id'];
            $commenterquery = "SELECT * FROM settings WHERE user_id=$commenterid";
            $commentersql = mysql_query($commenterquery) or die('SQL Error :: '.mysql_error());
            $commenterqueryrow = mysql_fetch_assoc($commentersql);
            $commentername = $commenterqueryrow['display_name'];
            echo '<div class="comment"><a href="mypage.php?user='.$commenterid.'">'.$commentername.'</a> said: '.stripslashes($commentrow['comment']).'';

            if ($login->isLoggedIn()) {
            // Has this user already reported this comment?
            $reportedcommentquery = "SELECT * FROM report WHERE comment_id=$commentid AND reporter_id=$userid AND listing_id=$listingid";
            $reportedcomment = mysql_query($reportedcommentquery) or die('SQL Error :: '.mysql_error());

        if (mysql_num_rows($reportedcomment) > "0") {
            echo '  <span class="small_gray">-Reported and under review-</span>';
            } else {
            echo '  <a href="item.php?item='.$listingid.'&report='.$commentid.'" class="small_graylink">Report</a>';
            }

            echo '</div>';

                // Get responses
                $responsesquery = "SELECT * FROM comments WHERE listing_id=$listingid AND response_to_id=$commentid ORDER BY comment_ts ASC";
                $responsessql = mysql_query($responsesquery) or die('SQL Error :: '.mysql_error());

                 if(mysql_num_rows($responsessql) == 0){ 
                    echo '';                        
                    } else {    
                    while($responsesrow=mysql_fetch_array($responsessql))
                    {
                    // Get responder display name from database
                    $responderid = $responsesrow['user_id'];
                    $responseid = $responsesrow['comment_id'];
                    $responderquery = "SELECT * FROM settings WHERE user_id=$responderid";
                    $respondersql = mysql_query($responderquery) or die('SQL Error :: '.mysql_error());
                    $responderqueryrow = mysql_fetch_assoc($respondersql);
                    $respondername = $responderqueryrow['display_name'];
                    $responderid = $responderqueryrow['user_id'];
                    echo '<div class="response"><a href="mypage.php?user='.$responderid.'">'.$respondername.'</a> said: '.stripslashes($responsesrow['comment']).'';

                    if ($login->isLoggedIn()) {
                        // Has this user already reported this comment?
                        $reportedresponsequery = "SELECT * FROM report WHERE comment_id=$responseid AND reporter_id=$userid AND listing_id=$listingid";
                        $reportedresponse = mysql_query($reportedresponsequery) or die('SQL Error :: '.mysql_error());

                    if (mysql_num_rows($reportedresponse) > "0") {
                    echo'  <span class="small_gray">-Reported and under review-</span>';
                    } else {
                    echo'  <a href="item.php?item='.$listingid.'&report='.$responsesrow['comment_id'].'" class="small_graylink">Report</a>';
                        }
                    }
                    }

                    echo '</div>';
                    echo '<div class="clear"></div>';
                        }
                    }

              // Response form
              if ($login->isLoggedIn()) {
              echo '<div class="responsebox">Respond to this comment:<br /><form id="newresponseto" name="newresponseto" method="post" action="item.php?item='.$listingid.'&comment='.$commentrow['comment_id'].'">
              <textarea name="new_response" cols="43" rows="2">'.$usercommentname.' says:</textarea><br />
              <input type="submit" name="Submit" value="Submit" /></form></div><hr>';
                              } else {
                              }
                }
            }

          // Comment form
          if ($login->isLoggedIn()) {
echo'         <div class="commentbox">Post a comment:<br /><form id="newcommentform" name="newcommentform" method="post" action="item.php?item='.$listingid.'">
            <textarea name="new_comment" cols="50" rows="2">'.$usercommentname.' says:</textarea><br />
            <input type="submit" name="Submit" value="Submit" />
          </form></div>';
          } else {
          echo '<div align="center">Log in to post comments or responses.</div>';
          }

Here is the corresponding CSS..

.comment {
    float: left;
    width: 100%;
    background-color:#CCCCCC;
    margin-bottom: 10px;

}

.commentbox {
    float: left;
    width: 100%;
    margin-bottom: 10px;
}

.response {
    float: left;
    background-color:#EDEFF4;
    margin-bottom: 10px;

}

.responsecontainer {
    float: left;
    margin-left: 10%;
    width: 90%;
    margin-bottom: 10px;
}

.responsebox {
    float: left;
    margin-bottom: 10px;
}

Any idea how to keep the nested looping, but force the responses (and actually any subsequent comments) to lay out without also looping the margin-left?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:44:03+00:00Added an answer on June 14, 2026 at 8:44 pm

    I don’t see in your posted code where you have called the .responsecontainer class, which would set the margin-left 10%.

    But the nesting of the responses are because you not closing your
    <div class="response"> in the while loop, only at the end after you close the loop. So you are going to get a situation like this –

    <div class="response"><a href="mypage.php?user=1">user1</a> said: Yes
    <div class="response"><a href="mypage.php?user=2">user2</a> said: I agree
    <div class="response"><a href="mypage.php?user=3">user3</a> said: Are You Sure?
    </div>
    

    So the last 2 would be nested into the 1st <div> rather then directly below.

    You need to add the <div class="responsecontainer"> around the response while loop, and then add the </div> inside the loop.

    Truncated script-

                // Get responses
                ...
                 echo '<div class="responsecontainer">';  // Add <div class="responsecontainer"> to make all responses margin-left 10% as a group 
                 if(mysql_num_rows($responsessql) == 0){ 
                    ...    
    
                    while($responsesrow=mysql_fetch_array($responsessql))
                    {
                    // Get responder display name from database
                    $responderid = $responsesrow['user_id'];
                    $responseid = $responsesrow['comment_id'];
                    $responderquery = "SELECT * FROM settings WHERE user_id=$responderid";
                    $respondersql = mysql_query($responderquery) or die('SQL Error :: '.mysql_error());
                    $responderqueryrow = mysql_fetch_assoc($respondersql);
                    $respondername = $responderqueryrow['display_name'];
                    $responderid = $responderqueryrow['user_id'];
                    echo '<div class="response"><a href="mypage.php?user='.$responderid.'">'.$respondername.'</a> said: '.stripslashes($responsesrow['comment']).'';
    
                    if ($login->isLoggedIn()) {
                        // Has this user already reported this comment?
                        $reportedresponsequery = "SELECT * FROM report WHERE comment_id=$responseid AND reporter_id=$userid AND listing_id=$listingid";
                        $reportedresponse = mysql_query($reportedresponsequery) or die('SQL Error :: '.mysql_error());
    
                    if (mysql_num_rows($reportedresponse) > "0") {
                    echo'  <span class="small_gray">-Reported and under review-</span>';
                    } else {
                    echo'  <a href="item.php?item='.$listingid.'&report='.$responsesrow['comment_id'].'" class="small_graylink">Report</a>';
                        }
                    }
                    echo '</div>';  // Missing </div> inside while loop
                    }
    
                    echo '</div>';  // Ends <div class="responsecontainer">
                    echo '<div class="clear"></div>';
                    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a comment section and a reply to comment section on my social
In my app I have a article and comment model. I implemented a reply-feature,
I hope I am clear enough. My data set is populated I have comment:CommentVO;
I have a Comment model in my app but am encountering a lot of
i'm learning EmberJS and building a comment section that allows 1 level of sub
I need to do the following: every comment have a reply button with a
I have a system of comments. Each comment may receive replies, and each reply
I have a line in my test: page.has_reply?(my reply).must_equal true and to make it
I am having comment reply (only till one level) functionality. All comments can have
I have code similar to the below <form action=/u method=post> <div class=reply> <input type=hidden

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.