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.

Link to comment
Share on other sites

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"
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.