I have an array with the data which I want to display with pagination.
$display_array = Array
(
[0] => "0602 xxx2",
[1] => "0602 xxx3",
[2] => 5 // Total= 2+3
[3] => "0602 xxx3",
[4] => "0602 saa4",
[5] => 7 // Total = 3+4
)
I have try some thing like this
function pagination($display_array, $page)
{
global $show_per_page;
$page = $page < 1 ? 1 : $page;
$start = ($page - 1) * $show_per_page;
$end = $page * $show_per_page;
for($i = $start; $i < $end; $i++)
{
////echo $display_array[$i] . "<p>";
// How to manipulate this?
// To get the result as I described below.
}
}
I want do a pagination to get the expected result like this:
If I define $show_per_page = 2;
then pagination($display_array, 1);
outputs:
0602 xxx2
0602 xxxx3
Total:5
And paganation($display_array, 2);
outputs:
0602 xxx3
0602 saa4
Total:7
If I define $show_per_page = 3;
, then pagination($display_array, 1);
outputs:
0602 xxx2
0602 xxxx3
Total: 5
0602 xxx3
And paganation($display_array, 2);
outputs:
0602 saa4
Total:7
If I define $show_per_page = 4;
outputs:
0602 xxx2
0602 xxxx3
Total:5
0602 xxx3
0602 saa4
Total: 7
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…