I am new to codeigniter, I am trying to create pagination on the records i am fetching from database. I have written the following code, its showing me pagination but its no
For a better use of pagination create a function in your helper. That will very useful for you for future use. you don't ever need to load library and other values. fix this function in your helper.
if( ! function_exists('createPaginationForm')) {
function createPaginationForm($url, $totalRows, $perPage, $segment, $queryString = '', $config = array()) {
$CI =& get_instance();
$CI->load->library('pagination');
$config['base_url'] = base_url().$url;
$config['total_rows'] = $totalRows;
$config['per_page'] = $perPage;
$config['uri_segment'] = $segment;
$CI->pagination->initialize($config);
return $CI->pagination->create_links($queryString);
}
}
and use in your controller .
var $perPage = '10';
var $segment = '4';
$total_result = "50";
$pagination = createPaginationForm('admin/news/index/',$total_result ,$this->perPage, $this->segment);
$this->data['pagination'] = $pagination;
and print this in your view.
echo $pagination