i'm doing a project of my friend, this was build using codeigniter and it runs wiith a template. so my problem is,when i'm using pagination it views correctly, but when i clicked second page button, it loads the same data on the main page.
here's my code..
controller for loading main template.
public function pg(){
$this->template->attach($this->resours);
$this->template->draw('student/view_pg',true);
$this->load->view('student/view_pg');
}
controller for loading pagination view.
function pg_index($offset=0,$order_column='st_id',$order_type='asc')
{
$this->load->helper('url');
//Check for valid column
if(empty($offset)) $offset=0;
if(empty($order_column)) $order_column='st_id';
if(empty($order_type)) $order_type='asc';
//load data
$Students=$this->Student_model->get_paged_list($this->limit,$offset,$order_column,$order_type)->result();
//print_r($Students);
//genarate pagination
$this->load->library('pagination');
//$config['base_url']=site_url('student/pg_index/');
$config['base_url']=site_url('student/pg/');
$config['total_rows']=$this->Student_model->count_all();
$config['per_page']=$this->limit;
$config['uri_segment']=3;
$this->pagination->initialize($config);
$data['pagination']=$this->pagination->create_links();
//genarate table data
$this->load->library('table');
$this->table->set_empty(" ");
$new_order=($order_type=='asc' ? 'desc' : 'asc');
$this->table->set_heading(
'St_id', 'name',
'address',
'number',
'email',
'Actions'
);
$i=0+$offset;
foreach($Students as $Student)
{
$this->table->add_row(++$i,
$Student->name,
$Student->address,
$Student->number,
$Student->email,
anchor('get_detail_st(<?php echo $value->st_id;?>);'.$Student->id,'update',array('class'=>'Delete')),
anchor('Student/delete/'.$Student->id,'delete',array('class'=>'Delete'))
);
}
$data['table'] = $this->table->generate();
$this->load->view('student/Student_pg_crud',$data);
}
the pagination view student_pg_crud
<body>
<div class="content">
<div class="data"><?php echo $table; ?></div>
<div class="paging"><?php echo $pagination; ?></div>
<br />
<?php echo anchor('Student/add/','Add new students',array('class'=>'add')); ?>
</div>
</body>
</html>
drawing main view. /view_pg
$_instance = get_instance()
?>
<table width="100%" border="0" cellpadding="10">
<tr class="ContentTableTitleRow" width="100%">
<td style="vertical-align: top" width="100%">View Student</td>
</tr>
<tr>
<td style="vertical-align: top"><?php $_instance->pg_index(); ?></td>
</tr>
</table>
what's wrong here.. i'm a begginer for codeigniter, is there any method than this to use templates in codeigniter?
Try with $config['base_url']=base_url('student/path/to/your/pagination/controller');
i think your controller is pg_index. echo
the value of every variable and check how many total records and what is uri_segment?