Why are pagination links not working for me in CodeIgniter?

后端 未结 2 1486
醉梦人生
醉梦人生 2021-01-27 08:58

I\'m trying to use codeigniter pagination for my products so there are multiple pages which products but its not working for me and I don\'t know why..

This is my pagina

2条回答
  •  死守一世寂寞
    2021-01-27 09:14

    You have a mix of code, pagination and not pagination results.

    Add,

    $config["num_links"] = 5; //Number of links in pagination
    

    After initilize Codeigniter pagination library. You have to execute a pagination query in your database, for example:

    $where = "IF you have got";
    $orderby "IF you have got";
    
    $data['products'] = $this->Pagination_model->select_products($config["per_page"], $this->uri->segment(3), $where, $orderby);
    

    Then in your model Pagination_model, you should have got this:

    public function select_products($per_page, $segment, $where, $orderby)
    {
        if (!isset($segment)) $segment = 1;
    
        $init= ($segment - 1) *  $per_page;
    
        $sql = "SELECT *
                  FROM Your_table
                  $where 
                  ORDER BY $orderby
                  OFFSET $init ROWS
                  FETCH NEXT $per_page ROWS ONLY";
    
        $query= $this->db->query($sql);
        return $query->result_array();
      }
    

    Be sure you are right point to this->uri->segment() is 3. I think you dont have pagination links because you dont have results in your query.

提交回复
热议问题