Is there a general method for implementing pagination through PHP data objects?
OOP is a very general question. You can design your CMS in one hundred OOP and non-OOP. Well, this is a common scenario for how pagination works:
In your controller:
and. Retrieve the total number of rows in a table
list ($ total_rowcount) = $ db-> query ('SELECT count (*) FROM table WHERE ... ");
B. Determine the total number of pages (in the table)
$ page_count = ceil ($ total_rowcount / $ Rowcount_per_page);
C. Extract rows for the currently selected page
$ start_element = $ page * $ Rowcount_per_page;
$ end_element = $ start_element + $ rowcount_per_page;
$ rows = $ db-> query ('SELECT count (*) FROM table WHERE ... LIMIT ". $ Start_element.', '. $ End_element);
In the template
D. show all items
$ rowcount_per_page = count ($ rows);
for ($ i = 0; $ i <$ rowcount_per_page; $ i ++)
{show ($ rows [$ i]); }
F. Show all page links
for ($ i = 0; $ i <$ page_count; $ i ++)
{echo ($ i == $ page? $ i: '<a href = "? page ='. $ i. '">'. $ i. '</a>'); }
What is it.
a source to share