<?php
$B = array(
0=>1,
1=>2,
2=>3,
3=>4,
4=>5,
5=>6,
6=>7,
7=>8,
8=>9,
9=>10,
10=>11
);
function pagination_from_array($arr, $show_per_page, $page=1){
$start = $show_per_page * ($page-1);
$end = $show_per_page * $page;
for($i = $start; $i < $end; $i++){
echo ">>>".$arr[$i]."<br>";
}
if($end-1 < count($arr)) {
echo '............';
}
}
pagination_from_array($B , 6, $_GET['page']);
/*
//Dislay in html table
//=> page1
key | value
0 1
1 2
2 3
3 4
4 5
5 6
........
//=> page 2
key | value
6 7
7 8
8 9
9 10
10 11
total 1+2+3+..+11
*/
?>
Could anyone help me to implement this?
Here is your problem:
$iis a negative number as$show_per_page * ($page-1);equals -6So when your referencing
$arr[$i]it’s not displaying anything because there is nothing at index -6, You could try something like the abs(), Example:UPDATE:
Well it’s actually this:
$_GET['page']that’s causing the negative value for the index in your example.UPDATE #2:
Well I went along and quickly created this, hope this gets you started: