/    Sign up×
Community /Pin to ProfileBookmark

Multiple pages depending on how many comments

I’m working on a website that allows users to submit reviews/comments on particular items. I was wondering how to write the website so it will display lets say only 12 comments on the first page, and then allow users to click on page 2, page 3, and so on. Depending on how many comments there actually are.

Thank you,
Scott G

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@TecBratDec 17.2011 — You'll count the number of comments you have. If you have more than the max allowed on the page then you list 1 through max and put up a "next page" link. That link will have something like "?page=2" at the end (or ?some_var=someval&page=2) when the page loads and $_GET['page'] is an integer greater than 1, you load max*(page-1)+1 through max*page. If there are more than max*page then you have a link that has "?page=(page+1)"

Pardon my psuedo code, Writing and thinking at the same time.

If you want to do a previous button, be careful that if page is 2, not to link with ?page=1 or you'll have 2 URLs for the same page and that's not good for SEO.
×

Success!

Help @ScottG89 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...