I'm building a relatively simple PHP forum and trying to add in a few nice features from some of the mainstream boards like phpBB.
The database structure is the simple 3 table approach. Categories, threads and posts.
I'm implementing a 'last post' feature for each category and thread. I already have the last post information as this is stored in the DB, that isn't the problem. What I'm trying to work out is how to link to this post in a thread which has paged replies, say 25 per page. If my post is number 26 of 26 how would you program the thread to go to page two? Say I wanted to permalink to post 30 of 90, how might you link to page 2 and ensure the correct number of replies/pages are either side?
I've been trying to work out how phpBB do it, but I figure you could spend all year ripping that apart and get no where. I see they pass the post_id as an additional parameter with the thread_id, but I can't work out how they use that information. Any ideas for a starting point? Thanks.
I've come up with a solution based on what @aditya-menon and @GeoPhoenix have said. I know the total posts already, so I've just divided that by the posts per page to get the total number of pages. The last post will always been on the last page so that's easy enough.
The challenge is working out which page a post falls on in the middle of a thread. I've run a BETWEEN
query like this to calculate how many posts into a thread a particular post is
SELECT COUNT(post_id) FROM posts
WHERE topic_id = $TOPIC_ID AND post_id BETWEEN 0 AND $POST_ID
Then divide posts per page by this number and ceil()
to give the page number the post is on.
Not so sure how efficient that query will be with a large forum but it seems to do the job. Thanks guys