【问题标题】:How to use pagination in Codeigniter如何在 Codeigniter 中使用分页
【发布时间】:2012-04-07 09:25:42
【问题描述】:

我已经从 XML 中提取了数百条记录到一个数组变量中。当数组被回显时,它的输出是:

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

【问题讨论】:

    标签: php codeigniter pagination


    【解决方案1】:

    怎么样:

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

    【讨论】:

    • 有效吗?如果是这样,并且您对我的回答感到满意,请您接受它吗?提前谢谢你。
    猜你喜欢
    • 2016-05-13
    • 2021-03-07
    • 2014-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-30
    相关资源
    最近更新 更多