2012-04-07 64 views
0

我已经从XML中将数百条记录提取到数组变量。当数组回显时,它的输出是:如何在Codeigniter中使用分页

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中使用分页?

回答

0

什么:

$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 
} 
+0

感谢kerwindena – npcoda 2012-04-09 07:08:16

+0

是否行得通?如果是这样,并且我对你的回答感觉良好,请你好好接受它吗?先谢谢你。 – Kerwindena 2012-04-09 16:28:31