Jump to content

MYSQL LIMIT. Show additional rows from database.


shortysbest

Recommended Posts

I have a commenting system and i have a limit of a certain number of comments to be shown. What i want to do is have a button on the bottom of the page at the end of the comments that are showing and when you click it ajax loads the next certain number of of rows (but not all of them),and then you click it again and it shows more of them, etc.

 

So for example.

 

comment 1

comment 2

comment 3

comment 4

--click button--(loads 4 more)---

comment 5

comment 6

comment 7

comment 8

--click button--(loads 4 more)--

comment 9

comment 10

comment 11

comment 12

 

etc. until there are no more rows.

 

what's the best way to do this? (I know how to do the ajax and all, i just need help with the script to select the rows)

 

Thanks.

It's basically just regular pagination: you tell the script which page you want, it figures out which range that corresponds to.

Like ajax.php?page=2 would get the HTML for comments 5-8. Your JavaScript then removes the old More link, inserts the new HTML, and inserts a new More link.

 

If you want to know whether the last four retrieved were the actual last four then your ajax.php can return an object instead of just the HTML string:

{
    "hasmore": false,
    "html": "html for the comments"
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.