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 7795931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:12:53+00:00 2026-06-01T23:12:53+00:00

I am making an ajax comment system for my website and I am querying

  • 0

I am making an ajax comment system for my website and I am querying my database for any comments with a certain field. I then look and see if the number of returned results is larger than 3, or less than/equal to 3(I have a specific reason for 3). If it is larger than 3, I set a variable = 3 but if it is less than/equal to 3, I set the variable equal to the number of returned rows(mysql_num_rows()). I then echo some text before the loop, then I echo the stuff in the loop and then after the loop I echo more stuff. For some reason my for loop is running more than the given times. What is very strange is that it is echoing the same comment 3 times before moving onto the next comment and echoing that 3 times. After the for loop, I have 9 comments in total. This dosn’t work with my design as I can only fit 3 comments where I am placing them. My for loop is nested in a few whiles because I need to query multiple times to get to the information I need based on the info I send to the php(specific reason for this also). Another thing, the PHP only echoes the comments 9 times only if the number of returned results is greater than 3 works fine if it is less than 3. I have been over this code 50 times but I can’t find anything. Maybe you guys can. Heres the code I am using:


                $comments = mysql_query("SELECT * FROM comments WHERE profid = '".$row['id']."'");
                $numComments = mysql_num_rows($comments);
                $totalCommComments = 0;
                if ($numComments > 0) {
                    if (mysql_num_rows($comments) > 3) {
                        $totalCommComments = 3;
                        echo '
        <div class="comments">
            <div class="commContainer">
                <ul class="'.$totalCommComments.'Comm">';
                        while ($get1 = mysql_fetch_array($comments)) {
                        for ($l = 1;$l<$totalCommComments;$l++) {
                            echo 'STUFF IS ECHOED HERE';
                        }
                        }  
                        echo '
                 </ul>
            </div>
       </div>';

I know the variable $totalCommComments is set to 3 because I can see the class in the <ul>.

PS. This isn’t the full code, only the relevant code. Everything else is querying different database for other information needed to make this query.


Thank you so much

  • 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-01T23:12:54+00:00Added an answer on June 1, 2026 at 11:12 pm
    $comments = mysql_query("SELECT * FROM comments WHERE profid = {$row['id']}");
    $numComments = mysql_num_rows($comments);
    if ($numComments > 0) { ?>
       <div class="comments">
           <div class="commContainer">
               <ul class="shortComments">
                   <?php $i = 0;
                   while ($i++ < 3 && $get1 = mysql_fetch_assoc($comments)) { ?>
                       <li class='comment'><?=$get1['comment']?></li>
                   <?php } ?>
               </ul>
           </div>
       </div>
    <?php } ?>
    

    try that. You have a lot of redundant code in there

    there are a lot of different ways i could continue to edit this, if you let us know what you are trying to do, i can update this code

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a comments system and each comments textarea gets a unique class.
Right so I'm making a news system that uses jQuery and AJAX for the
If your API and Website making ajax calls to that API are on the
Is there any other use for shebangs/hashbangs besides for making AJAX contents crawlable for
Background I'm writing an asynchronous comment system for my website, after reading plenty of
i am making ajax calls with jquery like this http://pastie.org/860837 and sometimes i get
I'm making AJAX calls to a server that sometimes return unparseable JSON. The server
I am making ajax call like this $(document).ready(function() { var abc = new Array();
I've rewritten my family web site using JavaScript (JQuery) making Ajax calls to PHP
I have a template set up that I'm making ajax calls to via jQuery.

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.