Hello. Tell me, please, in what way can I paginate a table? It is filled with records from the database, which are replenished every day.
- fivejust like any other pagination. what exactly is the question? - teran
- @teran, I have never paginated before, so I’m interested - Bipa
|
1 answer
Very pseudocode, however, helps to understand the essence:
// начальные данные $count = SELECT COUNT(*) FROM таблица ; // общее кол-во записей $itemPerPage = 10; // кол-во записей на страницу $pagesCount = round($count / $itemPerPage); // кол-во страниц пагинации // обработка запроса и формирование результатов if($_GET['page']) { $from = $itemPerPage * $_GET['page'] - 1; $to = $itemPerPage * $_GET['page']; $результатs = SELECT что-то FROM таблица LIMIT $from, $to; }else { $результатs = SELECT что-то FROM таблица LIMIT 0, $itemPerPage; } // выстраивание таблицы foreach($результатs) { // выводим данные } // выстраивание пагинации for( $i <= $pagesCount ) { // $i = 1 <a href="&page=$i">$i</a> // $_GET['page'] } - Thanks for the answer) But could you please explain what these results are and $ _GET ["page"]? - Bipa
- page is a get parameter, it is passed when clicking on the pagination link. Clicking on the page link in the pagination, the page reloaded, the if ($ _ GET ['page']) condition was checked - Kirill Korushkin
|