[英]How to use pagination in Codeigniter
我已經從 XML 中提取了數百條記錄到一個數組變量中。 當數組被回顯時,它的 output 是:
array(1) {
[“photo”]=>
array(2) {
[”@attributes”]=>
array(3) {
[“baseURL”]=>
string(36) “http://www.myurl.com/photos/event_name11”
[“thumbDir”]=>
string(5) “thumb”
[“largeDir”]=>
string(6) “images”
}
[“pr”]=>
array(228) {
[0]=>
array(1) {
[”@attributes”]=>
array(5) {
[“w”]=>
string(3) “650”
[“h”]=>
string(3) “433”
[“p”]=>
string(10) “194393.JPG”
[“n”]=>
string(6) “194393”
[“d”]=>
string(0) “”
}
}
[1]=>
array(1) {
[”@attributes”]=>
array(5) {
[“w”]=>
string(3) “650”
[“h”]=>
string(3) “433”
[“p”]=>
string(10) “194394.JPG”
[“n”]=>
string(6) “194394”
[“d”]=>
string(0) “”
}
}
我想在單個頁面中顯示總共 15 條記錄,每行 5 條。 圖片的名稱和尺寸位於:
[“pr”]=>
array(228) {
我試過使用其他 PHP 硬代碼,但無法獲得預期的結果。 它在單個頁面中顯示所有記錄。
如何在 CI 中使用分頁?
關於什么:
$array = ...
$page = 0; // the page number you want to display
$entriesPerPage = 5;
for($i = 0; $i < $entriesPerPage; $i++)
{
$entry = $array['pr'][$page * $entriesPerPage + $i];
// output your $entry somehow
}
或者如果你想獲得 3 行 â 5 信息:
$array = ...
$page = 0; // the page number you want to display
$entriesPerRow = 5;
$rowsPerPage = 3;
for($i = 0; $i < $rowsPerPage; $i++)
{
for($j = 0; $j < $entriesPerRow; $j++)
{
$entry = $array['pr'][($page * $rowsPerPage + $i) * $entriesPerRow + $j];
// output your $entry somehow
}
// make a new line
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.