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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:22:59+00:00 2026-06-06T11:22:59+00:00

I have a segment of my website which needs to dynamically load content when

  • 0

I have a segment of my website which needs to dynamically load content when the user reaches the bottom. I’m using jQuery, and this is the code to detect the scroll:

$(document).ready(function() { 
    $(window).scroll(function() {
        if($(window).scrollTop() + $(window).height() == $(document).height()) {
        alert("Bottom reached");
            $('div#loadMoreComments').show();
            dataStr = "from=" + $(".n:last").attr('id')
            $.ajax({
                type: "POST",
                url: "ajax/query.php",
                data: dataStr,
                success: function(html) {
                    if(html){       
                        $("#hold").append(html);
                        alert("Data was added");
                    }
                    else{       
                        $('div#loadMoreComments').replaceWith("<center><h1 style='color:red'>End of countries !!!!!!!</h1></center>");
                        alert("Data was not added");
                    }
                }
            });
        }
    });
});

The first problem I have is that the scroll to the bottom is only detected when the user reaches the top of the page. The second problem is that it doesn’t load any content, at all, because the variable doesn’t seem to be posted, here’s my code in the query.php:

if(array_key_exists('from', $_POST)) {
    $from = htmlspecialchars(stripslashes(mysql_real_escape_string($_POST['from'])));
    $to = 15;
    $re = ("SELECT status as status, sid as sid, UNIX_TIMESTAMP(timestamp) as timestamp FROM mingle_status WHERE uid = '$uid' ORDER BY timestamp DESC LIMIT $from,$to"); //query
  }
  else {
    $re = ("SELECT id as id, status as status, sid as sid, UNIX_TIMESTAMP(timestamp) as timestamp FROM mingle_status WHERE uid = '$uid' ORDER BY timestamp DESC LIMIT 1"); //query
  }
  $result = mysql_query($re) or die (mysql_error());
  while($st = mysql_fetch_assoc($result)) {
    $status = nl2br($st['status']);
    $sid = $st['sid'];  
    $td = $st['timestamp'];
    $id = $st['id'];
    ?>
        <div id="<?php echo $id; ?>" class="id">
            <!-- stuff -->
        </div>
    <?php
    }
    ?>

And the error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '",15' at line 1

If anyone could help me with this, it’d be great, I’d really appreciate it.

EDIT: Okay, I can now get a div generated, but only when I scroll to the top of the page, and it only appends one div, and if I scroll to the top again, it appends the exact same div.

  • 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-06T11:23:00+00:00Added an answer on June 6, 2026 at 11:23 am

    This is just wrong:

    $from = htmlspecialchars(stripslashes(mysql_real_escape_string($_POST['from'])));
    

    If from is supposed to be an integer, just use:

    $from = (int) $_POST['from'];
    

    I also see that that number comes from an id in the html and ids cannot start with a number.

    Edit: An additional problem is that you are not selecting the ID in your sql query if from exists and even if you would do that, this approach can lead to problems in the future when you delete records and your IDs are not sequential any more.

    About the first problem, I can solve that in firebug changing:

     if($(window).scrollTop() + $(window).height() == $(document).height()) {
    

    to:

     if( ($(window).scrollTop() + $(window).height()) > ($(document).height() -  10) ) {
    

    Edit 2: To solve your non-sequential ID problem, the easiest way would be to calculate from in javascript using something like:

    dataStr = "from=" + $(".n").length;    // just count the number of elements you are showing already
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example, I have a website which has a dynamically-generated segment of its dom
I have this segment of Scala code which defines an ordering and applies it
I have this code segment in which I am opening/closing a file a number
I have this segment of code: - (void)setTableView:(UITableView *)tableView { tableView = tableView; }
I have this segment of code , a lot of things skipped for brevity
I have this segment of XML: <mvc:interceptors> <mvc:interceptor> <mvc:mapping path=/statics/** /> <bean class=com.company.website.servlet.StaticsHandlerInterceptor />
I have a code segment which is as simple as : for( int i
I have a segment of HTML code which includes a conditional comment: <!--[if IE]>
Hey, I have a code segment here: <div class=label><%= f.label :course %> <span>(Does this
If we have this segment of code: char *i=Hello; cout<<i<<endl; cout<<*i<<endl; cout<<&i<<endl; cout<<*&i<<endl; cout<<&*i<<endl;

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.