tags:

views:

38

answers:

2

When I do pagination for my comments my numbering for my comments starts over on the next page how can I fix this so my count of the comments wont start over for my comments? When I leave out pagination my numbering of my comments works fine. Im using PHP & MySQL.

My counting for my comments is simple

$comment_num = 1; //number comments posted

How I display the numbered comment.

echo '<div>' . $comment_num++ . '</div>';

Display output without pagination.

Comment 1
Comment 2
Comment 3
Comment 4
Comment 5
Comment 6

Display count with pagination set to display 2 comments at a time.

Comment 1
Comment 2

Next pagination page with different comments.

Comment 1
Comment 2
+2  A: 

I'm assuming that you are running your query with a LIMIT and offset. Store the offset in a variable then use this:

$query = "SELECT * FROM yourtable LIMIT $offset, 2"

...

$comment_num = $offset + 1;
Mark Byers
what do you mean offset?
needIT
Erm, the offset you're using to actually get the paginated results?
Wrikken
I get the pagination results from a different query that does not actually count all the comments.
needIT
@needIT: If you're not using LIMIT and offset to implement paging, perhaps you could tell us how you are doing it? Post your SQL for example.
Mark Byers
I'm using Limit to display my comments
needIT
@needIT: OK, but my question is are you using an offset on your LIMIT? If not, then how do you know what the first record of the page is? Please post your SQL.
Mark Byers
I'm counting parent comments only for my pages and not the replies but when I number my comments I want to count all comments and replies.
needIT
A: 

Do you always show a fixed number of comments on a page? If so, you can start the numbering of a page at

( ( page_number - 1 ) * no_of_comments_on_page ) + 1

Say you show ten comments on a page, for page one you'd get: (0 * 10) + 1 = 1 for page two you'd get ( 1 * 10 ) + 1 = 11 and so on.

Steve Claridge
but what if the comments have replies?
needIT
They're still a comment through, right? You need to post more information if you want a more precise answer - we're just guessing at how your code might look.
Steve Claridge