//SELECT * FROM tbl LIMIT 5,10; # Retrieve rows 6-15
$input = array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19");
print_r(array_slice($input,5,10));
Output:
Array
(
[0] => 6
[1] => 7
[2] => 8
[3] => 9
[4] => 10
[5] => 11
[6] => 12
[7] => 13
[8] => 14
[9] => 15
)
Complete Pagination Example:
function PaginateArray($input, $page, $show_per_page) {
$page = $page < 1 ? 1 : $page;
$start = ($page - 1) * ($show_per_page);
$offset = $show_per_page;
$outArray = array_slice($input, $start, $offset);
var_export($outArray);
}
$input = array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20");
//page 1
PaginateArray($input, 1, 3);//inputs: array, page, records per page
/*
array (
0 => '1',
1 => '2',
2 => '3',
)
*/
//page 2
PaginateArray($input, 2, 3);//inputs: array, page, records per page
/*
array (
0 => '4',
1 => '5',
2 => '6',
)
*/
[ view entry ] ( 1527 views ) | print article
<<First <Back | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | Next> Last>>