0

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 Answers 2

2

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;
Sign up to request clarification or add additional context in comments.

6 Comments

Erm, the offset you're using to actually get the paginated results?
I get the pagination results from a different query that does not actually count all the comments.
@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.
I'm using Limit to display my comments
@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.
|
0

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.

2 Comments

but what if the comments have replies?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.