Php array paging implementation method, php array Paging
This article describes how to implement php array paging. We will share this with you for your reference. The details are as follows:
<? Php $ arr_click = array ('clicks' => 3, 'clickdate' => '2017-10-11 '), array ('clicks' => 2, 'clickdate' => '2017-10-10 '), array ('clicks' => 3, 'clickdate' => '2017-10-09 '), array ('clicks' => 4, 'clickdate' => '2017-10-08 '), array ('clicks' => 5, 'clickdate' => '2017-10-13 '), array ('clicks' => 7, 'clickdate' => '2017-10-14 '), array ('clicks' => 6, 'clickdate' => '2017-10-15 '), array ('clicks' => 9, 'Clickdate' => '2017-10-16 '),); if (! Isset ($ _ GET ['page']) {$ page = 1 ;}else {$ page =$ _ GET ['page'] ;}$ size = 3; // number of records displayed per page $ pnum = ceil (count ($ arr_click)/$ size); // total number of pages, ceil () the function is used to evaluate the smallest integer greater than the number. // use the array_slice (array, offset, length) function to retrieve a value in the array according to the conditions. array (array ), offset (starting position of the element), length (group length) $ newarr = array_slice ($ arr_click, ($ page-1) * $ size, $ size ); for ($ I = 0; $ I <count ($ newarr); $ I ++) {echo $ newarr [$ I] ['clickdate']. "<br/>" ;}?> <? Phpif (! Isset ($ _ GET ['page']) | $ _ GET ['page'] <= 1) {?> <A href = "111111111111.php? Page = 1 "> previous page </a> <? Php} else {?> <A href = "111111111111.php? Page = <? Php echo $ page-1;?> "> Previous page </a> <? Php }?> <? Php if ($ _ GET ['page'] >=$ pnum) {?> <A href = "111111111111.php? Page = <? Php echo $ pnum;?> "> Next page </a> <? Php} else {?> <A href = "111111111111.php? Page = <? Php echo $ page + 1;?> "> Next page </a> <? Php }?>