在codeigniter中分页并将值传递给控制器​​函数但分页不起作用

时间:2014-01-23 13:05:37

标签: codeigniter

控制器文件:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Departments extends CI_Controller {

    function __construct()
    {
        parent:: __construct();
        $this->load->model('login_model','',TRUE);
        $this->load->model('pariskarmodel','',TRUE);


    }

    public function index($id)
    {


            $this->load->library("pagination");
            $config = array();
            $config["base_url"] = base_url() . "departments/index";
            $config["total_rows"] = $this->pariskarmodel->mng_departments_count_check($id);
            $config["per_page"] = 3;
            $config["uri_segment"] = 3;
            $this->pagination->initialize($config);
            $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
            $data['news_data']=$this->pariskarmodel->mng_departments_check($config["per_page"],$page,$id);
            $data["links"] = $this->pagination->create_links();
            $this->load->view('departments',$data);
    }

}

 ?>

查看页面:

<u>
 <li><a href="<?php echo base_url();?>departments">Departments</a></li>
<li ><a href="<?php echo base_url();?>departments/index/1">Film</a></li>
<li><a href="<?php echo base_url();?>departments/index/2">TV</a></li>
<li><a href="<?php echo base_url();?>departments/index/3">Game</a></li>
<li><a href="<?php echo base_url();?>departments/index/4">Commercials</a></li>
<li><a href="<?php echo base_url();?>departments/index/5">Events & Awards</a></li>
             .
             .
             .
<li><a href="<?php echo base_url();?>departments/index/15">Events & Awards</a></li>
</ul>

模特页面:

function mng_departments_check($limit,$start,$id)
        {

        echo $sql="select * from tbl_departments where category='$id'  order by id DESC  limit $start,$limit";

            $query=$this->db->query($sql);
            return $query->result();
        }
        function mng_departments_count_check($id)
        {
            $sql="SELECT * FROM tbl_departments where category='$id' order by id DESC";
            $query=$this->db->query($sql);
            return $query->num_rows();
        }

结果是:当我点击链接一个(文件)sql查询是:

select * from tbl_departments where category='1' order by id DESC limit 1,3

点击链接二(文件)sql查询是:

select * from tbl_departments where category='2' order by id DESC limit 2,3 

如果我点击链接15 sql查询是:

select * from tbl_departments where category='15' order by id DESC limit 15,3 

我不能为什么类别(category = '15')是sql中的更改而且分页也不起作用。我把$ this-&gt; uri-&gt; segment(4)也行不通。

1 个答案:

答案 0 :(得分:1)

尝试:

$config["base_url"] = base_url() . "departments/index/".$id;

如果有帮助的话 请将其标记为答案..