Below is the code that I found (thanks to The_Sumo) on this link and the code works like a charm. I am trying to add an additional column to the table that displays the ordered list number of the users like:

1 John Doe [email protected]

2 Jane Doe [email protected]

One method I tried that kinda worked - i.e. I created a counter before the condition statement ($counter = 0).

Then right after the opening bracket of the foreach loop, I am incrementing the counter by 1 ($counter = $counter + 1;) and printing the value of $counter within the table.

The issue I am facing is - when I click next page, the counter value starts from 1 again instead of continuing from where it left of.

So lets say I want to display 5 items in each page, so page 1 should display 1 - 5 and on page 2 6-10 - instead page 2 shows 1-5 again. Just the numbers. Any idea how to fix that? Thanks.

1 Answer 1


You can try:

$number = $counter + ( $current_page - 1 ) * $users_per_page; 

with your increasing $counter variable in the loop.

Here we assume $counter >= 0, $current_page >= 1 and $users_per_page >= 1.

We might combine it into:

$number = ++$counter + ( $current_page - 1 ) * $users_per_page; 

with $counter = 0 as initial condition.


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.