限制php中的数组列表[关闭]

I would like to know how i limit a comments list(array) or a table list.

Because i´m making a web site and users can make posts and comments but i want limit it by page. Because if not it goes to infinite.

How i do that, for comments and posts(the posts are in a table)??

I´m using php by the way.

Thanks for answers.

You'll largely be relying on the LIMIT clause of your query. This will let you return a fixed number of results, starting from any index. So the first ten records could be returned with:

SELECT foo, bar FROM comments WHERE post_id = 5 LIMIT 0, 10 

Note, the 0 is not required, but it makes the next example easier to understand.

The second 10 could be returned with:

SELECT foo, bar FROM comments WHERE post_id = 5 LIMIT 11, 10

Typically you're store a $page variable in the URL and perform a bit of math against this, and the total number of comments per page to determine what your offset should be.