分页一直显示相同的数据

时间:2019-05-23 11:11:42

标签: php codeigniter pagination

我已经尝试了教程中的许多代码,但是当我单击分页时,它一直向我显示相同的数据。 我正在使用AdminLTE主题。也许就是这个问题

控制器

public function view_blog()
    {
        $this->load->model("blog_model");
        $this->load->library("pagination");

        $config = array();
        $config["base_url"] = base_url() . "blog/Blog/view_blog/";
        $config["total_rows"] = $this->blog_model->count_blog();
        $config["per_page"] = 2;
        $config["uri_segment"] = 5;
        $this->pagination->initialize($config);
        $page = ($this->uri->segment(5)) ? $this->uri->segment(5) : 0;

        $data["view_data"] = $this->blog_model->view_data($config["per_page"], $page);
        $data["links"] = $this->pagination->create_links();
        $data['view'] = 'blog_view/view_blog';
        $this->load->view('admin/layout', $data);

    }

型号

 public function view_data($limit,$start)
    {
        $query= $this->db->get("blog", $limit, $start);
        return $query->result();
    }

 public function count_blog(){
        return $this->db->count_all("blog");
    }

查看

<div class="content">
    <?php
        foreach ($view_data as $row){
    echo'    <div class="row">
        ....
    </div>';
    }
    ?>

    <?php echo $links; ?>
</div>

当我单击第2页时,应该会出现下两个博客

2 个答案:

答案 0 :(得分:1)

尝试使用method BinarySearchInsertionHint(a: seq<int>, key: int) returns (r: int) requires forall i,j :: 0 <= i < j < |a| ==> a[i] <= a[j] ensures 0 <= r <= |a| ensures forall i :: 0 <= i < r ==> a[i] <= key ensures r < |a| ==> forall i :: r <= i < |a| ==> key < a[i] { var lo, hi := 0, |a|; while lo < hi decreases hi - lo invariant 0 <= lo <= hi <= |a| invariant forall i :: 0 <= i < lo ==> a[i] <= key invariant forall i :: hi <= i < |a| ==> key < a[i] { var mid := (lo + hi) / 2; assert(lo <= mid < hi); if a[mid] <= key { lo := mid + 1; } else if key < a[mid] { hi := mid; } } assert(lo == hi); r := lo; } method Main() { var a := [0, 1, 1, 1, 2]; var hint := BinarySearchInsertionHint(a, 1); assert hint == 4; // assertion violation print hint; } 代替$config["uri_segment"] = 4;

我会检查5是否是您uri段页码的正确偏移量。根据{{​​3}},1是base_url()之后的第一段。如果遵循URI documentation的默认值,则页码将紧随在类中配置的base_url之后。由于您的$ config ['base_url']设置为“ blog / Blog / view_blog /”,因此正确的$ config ['uri_segment']将为4而不是5。

您还希望将$config["uri_segment"] = 5;更改为$page = ($this->uri->segment(5)) ? $this->uri->segment(5) : 0;

答案 1 :(得分:1)

在控制器中:

如果完全是$config["base_url"] = base_url() . "blog/Blog/view_blog/";

更改1

> $config["uri_segment"] = 5;

> $config["uri_segment"] = 4;

更改2

> $page = ($this->uri->segment(5)) ? $this->uri->segment(5) : 0;

> $page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;