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

  • Home
  • SEARCH
  • 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 9172655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:24:04+00:00 2026-06-17T16:24:04+00:00

I am trying to construct an AJAX-based infinite scroller with jQuery, PHP & mySQL.

  • 0

I am trying to construct an AJAX-based infinite scroller with jQuery, PHP & mySQL.

Pretty straightforward, there is a div in a primary page holding regular content (#theContent). When the window is scrolled to the bottom, a call is automatically made to an external PHP page (articles.php) which queries a mySQL database, then appends that new PHP content to the end of div#theContent in the primary page. This will last as long as there is new content in the recordset, using a passed offset variable from the primary to the external page.

I have it partly working, but could use some advice on the offset. In the code snippet below (from the primary page) you’ll see “articles.php?offset=10” – I want to increment the “offset” value each time the page is appended (when it scrolls to the bottom), so that the offset value is updated each time the .append(data) is called. This is where I am stuck.

In the head of the primary page (this scroll works, and the initial call to the database executes):

<script>
$(window).scroll(function () {
   if ($(window).scrollTop() >= $(document).height() - $(window).height() - 10) {

    $.get('articles.php?offset=10', function(data) {
        $('#theContent').append(data);
    });


       }
});
</script>

in articles.php (works by itself)

$offset = $_GET["offset"]; // gets from primary page  

the SQL call:
    "Select blah from blah order by blah limit 50,$offset";

So to sum up: how do I increment the offset variable in the primary page each time the .append is called?

Thanks for reading.


EDIT: I edited the snippet fr Ohgodwhy, moving the offset incrementer outside the $.get. Great – now the looping the same records problem is gone. Edits made:

 var offset = 10;
$(window).scroll(function () {

    if ($(window).scrollTop() >= $(document).height() - $(window).height() - 200) {

        $.get('articles.php?offset='+offset, function(data) {
            $('#theContent').append(data);

        });

  offset += 10;
        }
});
  • 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-17T16:24:05+00:00Added an answer on June 17, 2026 at 4:24 pm
    var offset = 10;
    $(window).scroll(function () {
        if ($(window).scrollTop() >= $(document).height() - $(window).height() - 10) {
    
            $.get('articles.php?offset='+offset, function(data) {
                $('#theContent').append(data);
                offset += 10;
            });
    
    
            }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to construct google charts using a ajax response form PHP file.
I'm trying to find where jQuery.ajax() is defined in their source code. However, using
I'm trying to figure out how to use jQuery AJAX with Python's Bottle module.
Hi I'm currently learning about the AJAX in jQuery and now I'm trying to
Currently Im trying to do ajax request using jQuery Mobile. I`m trying to use
I am just trying to learn how to use JQuery AJAX with ASP.NET MVC
I am trying to complete the tutorial at http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=438 It seems that the servlet
I am currently trying to construct a somewhat tricky MySQL Select Statement. Here is
I have a problem with my JQuery, Ajax, and PHP code. I have a
I am trying to pass a dataString to to an ajax call using 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.