A
A
Alex Mirgorodskiy2018-03-19 16:31:09
PHP
Alex Mirgorodskiy, 2018-03-19 16:31:09

How to calculate the page on which the message is located, if it is constantly changing?

Hello friends, who ever wrote the pagination himself? can you tell me how to calculate the page number where the message is, knowing the message id and the total number of messages? I sort in the reverse order, and therefore, if the SMS was on the 2nd page, after adding another 10 entries, it will be on the other one ... Can you tell me the formula or function how to calculate the page number where the SMS is now?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Vekov, 2018-03-19
@AlexWeb6667

Well, you need, for example, ceil(14/10). This is valid if your SMS is the 14th, and there are 10 elements on the page.
That is,
$currentID = 14;
$maxPageElements = 10;
$currentPage = ceil($currentID/$maxPageElements);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question