Php 在Codeigniter分页中设置当前页面
下面是我的代码,我不知道为什么它总是保持第一页作为当前页。这就是为什么下一个链接也不起作用。 我还尝试了Php 在Codeigniter分页中设置当前页面,php,codeigniter,twitter-bootstrap-3,Php,Codeigniter,Twitter Bootstrap 3,下面是我的代码,我不知道为什么它总是保持第一页作为当前页。这就是为什么下一个链接也不起作用。 我还尝试了$config['uri_segment']=1但不工作。 问题在哪里 $data['mukkadam_list'] = $this->get_mukkadam(); $data['from'] = $from; $data['to'] = $to; $data['mukkadam'] = $mukkadam; $url = base_url('Report/t
$config['uri_segment']=1代码>但不工作。
问题在哪里
$data['mukkadam_list'] = $this->get_mukkadam();
$data['from'] = $from;
$data['to'] = $to;
$data['mukkadam'] = $mukkadam;
$url = base_url('Report/teee/'.$from.'/'.$to.'/'.$mukkadam);
$config['base_url'] = $url;
$config['per_page'] = 50;
// Reports is model.
$config['total_rows'] = $this->Reports->counter($data['from'],$data['to'],$data['mukkadam']);
$config['num_links'] = $config['total_rows']/50;
$this->load->library('pagination');
$this->pagination->initialize($config);
谢谢。:) //选择query对所有可能的记录进行计数,并将其分配到此处
//$count=
//产品分页
$config['base\u url']=base\u url()index.php/report/teee/;
$config['total_rows']=$count;
$config['per_page']=50;
$config['uri_段]]=3;
$limit=$config['每页'];
//引导样式
$config['full_tag_open']=';
$config['full_tag_close']='
';
$config['first_link']=false;
$config['last_link']=false;
$config['first_tag_open']='';
$config['first_tag_close']=' ;
$config['prev_link']='laquo';
$config['prev_tag_open']='';
$config['prev_tag_close']=' ;
$config['next_link']='raquo';
$config['next_tag_open']='';
$config['next_tag_close']=' ;
$config['last_tag_open']='';
$config['last_tag_close']=' ;
$config['cur_tag_open']=';
$config['num_tag_open']='';
$config['num_tag_close']=' ;
$this->pagination->initialize($config);
$page=($this->uri->segment(3))$此->uri->段(3):0;
$data['links']=$this->pagination->create_links();
$data['dataSource']=$this->Sample\u Model->select\u query\u for\u get\u data($limit,$page);
在Codeigniter中执行分页时,需要记住两件事:
第一件事与页面生成相关的配置,实际上是:
// Loads pagination library
$this->load->library('pagination');
// @params $url = your controller + method path
$config['base_url'] = base_url() . $url;
// @params $totalRows = Total result found in query
$config['total_rows'] = $totalRows;
// @params $perPage = In your case it is 50
$config['per_page'] = $perPage;
// @params $segment = This is what you are missing in your code. Segment is the factor from where system reads which page records need to be shown
$config['uri_segment'] = $segment;
$this->pagination->initialize($config);
第二件事与设计零件相关的分页配置:
$config['full_tag_open'] = '<ul class="pagination pagination-sm m-t-none m-b-none">';
$config['full_tag_close'] = '</ul>';
$config['prev_link'] = '<i class="fa fa-chevron-left"></i>';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '<i class="fa fa-chevron-right"></i>';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['first_link'] = '<i class="fa fa-chevron-left"></i> <i class="fa fa-chevron-left"></i>';
$config['last_link'] = '<i class="fa fa-chevron-right"></i><i class="fa fa-chevron-right"></i>';
$this->pagination->create_links();
$config['full_tag_open']=';
$config['full_tag_close']='
';
$config['prev_link']='';
$config['prev_tag_open']='';
$config['prev_tag_close']=' ;
$config['next_link']='';
$config['next_tag_open']='';
$config['next_tag_close']=' ;
$config['cur_tag_open']=';
$config['num_tag_open']='';
$config['num_tag_close']=' ;
$config['first_tag_open']='';
$config['first_tag_close']=' ;
$config['last_tag_open']='';
$config['last_tag_close']=' ;
$config['first_link']='';
$config['last_link']='';
$this->pagination->create_links();
这是我在项目中使用的运行脚本。工作很好。您需要检查初始化期间传递的uri\u段
如果您遇到任何问题,请告诉我。试试这个-
$config = array();
$config["base_url"] = base_url() . "index.php/controller/methods";
$config["total_rows"] = $this->db->count_all("db_table_name");
$config["per_page"] = 20;
$config["uri_segment"] = 3;
$this->load->library("pagination");
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["results"] = $this->db->limit($config["per_page"],$page)->get("db_table_name")->result();
$data["links"] = $this->pagination->create_links();
$this->load->view('view_page',$data);
view_page.php-
<table class="table-bordered">
<?php foreach($results as $v){?>
<tr>
<td><?php echo $v->col1; ?></td>
<td><?php echo $v->col2; ?></td>
</tr>
<?php } ?>
</table>
<?php print_r($links); ?>
您无需从到分割链接和计算行数。。照原样做就行了。你可以提供一个例子吗?我现在尝试了很多事情,我不知道该怎么做。告诉我你的url是什么样子的<代码>报告/teee/
它显示的是这一点吗??。这里550是数据fatch的起始范围,限制是静态的,即50。其他是我的论点。
<table class="table-bordered">
<?php foreach($results as $v){?>
<tr>
<td><?php echo $v->col1; ?></td>
<td><?php echo $v->col2; ?></td>
</tr>
<?php } ?>
</table>
<?php print_r($links); ?>