I guess in short, you set up a file called something like getmore.php. That PHP file connects to the database and gets whatever it needs. It probably accepts POST parameters to adjust what it’s getting. Then you have an event on your page that JavaScript is watching. Like a click handler on a button. When that event fires, you do your AJAX thing pulling from the getmore.php file. Upon success of the AJAX event, you append what it returns to the page.
I know that’s rather abstract, but that’s how it works.