I was wondering how can I number my comments using PHP & MySQL and keep the correct comment number when using pagination? A brief example or tutorial would help. Thanks
Example output.
COMMENT 1
COMMENT开发者_C百科 2
COMMENT 3
Start your comment numbering at ($pageNumber * $commentsPerPage + 1)
(assuming page 0 is the first), and increment it for each comment.
If comments can skip numbers (for example, if you don't want deleting one comment to bump all the other comment numbers), then you might wanna consider storing the comment number in the database with the comment.
Your question is a bit cryptic, but assuming you have your query in place, well, I think you already know the initial offset.
Say you have something like this:
SELECT col_1, col_2
FROM my_table
ORDER BY col_3
LIMIT $offset, $num_rows
$offset + 1 will be the number of your first record (if you want 1-based numbers). Then in your php loop, increment this counter in each iteration.
What about identifying and labeling with timestamps? Just a thought... Using seconds would probably be enough to get unique numbers, unless the volume is huge... Then if any comments were removed, the id#s for the remaining comments would be unchanged... Like I said... just a thought...
精彩评论