I'm having some problems with Codeigniter and the pagination. The problem is that I get all the results/posts on all pages.
I'm having some problems with Codeigniter and the pagination. The problem is that I get all the results/posts on all pages.
Here is my Controller Code:
public function __construct()
{
parent::__construct();
$this->load->model('SS_shilpi_model');
$this->load->library('form_validation');
$this->load->library('pagination');
}
public function category(){
$cid = $this->input->post('cid');
if(isset($_GET['cid']))
{
$cid = $_GET['cid'];
$this->SS_shilpi_model->catr3($cid);
$this->SS_shilpi_model->catr3_nr($cid);
}
$config = [
'base_url' => base_url('category/?cid='. $cid .' '),
'per_page' => 12,
'total_rows' => $this->SS_shilpi_model->catr3_nr($cid),
];
$config['full_tag_open'] = '<ul style="overflow: hidden;" class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['num_tag_open'] = '<li class="page-item">';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="page-item active"><a class="page-link" href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['next_tag_open'] = '<li class="page-item">';
$config['next_tagl_close'] = '</a></li>';
$config['prev_tag_open'] = '<li class="page-item">';
$config['prev_tagl_close'] = '</li>';
$config['first_link'] = 'First <i class="fa fa-caret-left fa-2x push-left-5 pull-right green-text"></i>';
$config['first_tag_open'] = '<li class="page-item disabled">';
$config['first_tagl_close'] = '</li>';
$config['last_link'] = '<i class="fa fa-caret-right fa-2x push-left-5 pull-right green-text"></i> Last';
$config['last_tag_open'] = '<li class="page-item">';
$config['last_tagl_close'] = '</a></li>';
$config['attributes'] = array('class' => 'page-link');
$this->pagination->initialize($config); // model function
$data['catr3d'] = $this->SS_shilpi_model->catr3($cid, $config['per_page'], $this->uri->segment(3)); // list of Category Details
// end pagination
$this->load->view('shilpi/category',$data);
}
My Model Code :
public function catr3($cid){
$this->db->select('');
$this->db->order_by('id', 'DESC');
$this->db->where('category_id',$cid);
$query = $this->db->get('all_posts');
return $query->result();
}
public function catr3_nr($cid){
$this->db->select('');
$this->db->order_by('id', 'DESC');
$this->db->where('category_id',$cid);
$query = $this->db->get('all_posts');
return $query->num_rows();
}
My view code :
<div id="catdata" class="col-xs-12 no-pull push-up-5 push-down-5 briefs">
<?php
$count =1;
foreach($catr3d as $r)
{
if($count%4 == 1)
{
echo '<div class="col-xs-12 no-pull push-down-5">';
}
?>
<div class="col-sm-3 col-xs-12 no-pull-left pull-right-5">
<div class="brief whitish-bg pull-5">
<p class="red-text no-push">
<?php echo $r->short_title; ?>
</p>
<a href="<?php echo base_url(); ?>details/?pid=<?php echo $r->id; ?>">
<h5 class="blue-text font17 push-up-5">
<?php echo $r->title; ?>
</h5>
</a>
<p>
<a href="<?php echo base_url(); ?>details/?pid=<?php echo $r->id; ?>">
<img src="<?php echo base_url(); ?>upload/images/<?php echo $r->photo;?>" height="75" width="100" class="pull-left push-right-5 push-up-5"></img>
</a>
<?php
$string = $r->news;
$string = strip_tags($string);
if (strlen($string) > 500) {
$pos=strpos($string, ' ', 900);
$stringCut=substr($string,0,$pos );
echo $stringCut;
}
else {
echo $string;
}
?>
<i class="fa fa-caret-right fa-2x push-left-5 pull-right green-text"></i>
</p>
</div>
</div>
<?php
if ($count%4 == 0)
{
echo "</div>";
}
$count++;
?>
<div class="clear: both"></div>
<?php
}
if ($count%4 != 1) echo "</div>";
?>
<?= $this->pagination->create_links() ?>
</div>
Add This to Controller start and limit to your model function argument
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data['posts'] = $this->post->get_posts($config["per_page"], $page);
And following to model function get_posts
$this->db->limit($limit, $start);
Related
I am trying to create a simple pagination in my CodeIgniter blog, here is my code, I am using auto loader for these
$autoload['libraries'] = array('database','session','pagination');
$autoload['helper'] = array('form','url');
My Controller;
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Blog extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('BlogModel');
}
public function index($offset=0)
{
$this->load->library('table');
$config["base_url"] = base_url('blog');
//$config["total_rows"] = $this->BlogModel->get_Count(); // There are currently 36 Posts
$config["total_rows"] = 36; // There are currently 36 Posts
$config["per_page"] = 5; // Change limit to suit what you would like
$config['use_page_numbers'] = TRUE;
$limit = $config['per_page'];
$this->pagination->initialize($config);
$blog_pagination = $this->pagination->create_links();
$Posts = $this->BlogModel->get_Posts($limit, $offset);
$assignData=array('data'=>$Posts,'blog_pagination'=>$blog_pagination);
$this->load->view('header');
$this->load->view('blog', $assignData);
$this->load->view('footer');
}
}
I Have this in my Model;
<?php
class BlogModel extends CI_Model {
public function __construct(){
// Call the Model constructor
parent::__construct();
$this->load->library('memcached_library');
}
public function get_Posts($limit, $offset){
$this->db->select('*');
$this->db->where('post_status','published');
$query= $this->db->get('cms_posts',$limit, $offset);
$data=$query->result_array();
return $data;
}
public function get_Count() {
//$query = $this->db->get($this->db->dbprefix . 'blog');
$this->db->select('*')->from('cms_posts');
$this->db->where('post_status','published');
$query= $this->db->get();
//$data=$query->result_array();
return $query->num_rows();
}
}
?>
I am using this in my View;
<div id="primary" class="left-column">
<?php
if(!empty($data)){
foreach($data as $row){
?>
<main id="main" role="main">
<article id="<?php echo $row['post_id']; ?>" class="post-item">
<div class="right">
<div class="post-thumbnail">
<img src="<?php echo base_url()."assets/images/uploads/test_n-150x150.jpg";?>" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" sizes="(max-width: 320px) 100vw, 320px" width="320" height="143">
</div>
<!-- END .post-thumbnail -->
</div>
<div class="left">
<h2 class="post-title">
<?php echo $row['post_title']; ?>
</h2>
<div class="post-meta">
<span class="vcard author">
<?php echo ucwords($row['post_author']); ?>
</span>
<time class="entry-date published" datetime="<?php echo $row['post_date']; ?>"><?php echo date("d M Y", strtotime($row['post_date'])); ?></time>
</div>
<div class="post-excerpt">
<p>
<?php
echo(substr($row['post_content'], 0, 250));
<a class="read-more" href="<?php echo base_url()."blog/".$row['post_url']; ?>">Read More »</a>
</p>
</div>
<!-- END .post-excerpt -->
</div>
<!-- END .left -->
</article>
<!-- END .post-item -->
</main>
<?php
}
}
?>
<!-- END .site-main -->
<div class="pagination-wrap">
<?php echo $blog_pagination; ?>
</div>
</div>
EDIT:
My Route is as under:
$route['default_controller'] = 'index';
$route['blog/:any'] = 'blog/post/$1';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
I don't know that what and where are I am missing something, please lead me or correct me in this code. thnk you
Update
My Blog show now 5 Post on First Page and create Pagination but on only 123>Last› pagination is created and there is page blank on offset 2 (/blog/2).
maybee you can use my methode use uri segment to $offset, like this
public function house()
{
$config['base_url'] = site_url().'/user/house/';
$config['total_rows'] = $this->houses->select_row_house_design();
$config['per_page'] = 12;
$config['cur_tag_open'] = '<li><a><b>';
$config['cur_tag_close'] = '</li></a></b>';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$this->pagination->initialize($config);
$from = $this->uri->segment('3');
$data['design'] = $this->houses->select_all_house_design($config['per_page'],$from);
$title['menu'] = 'house design';
$this->template('user/house',$data,$title);
}
set controller like this,
this is also simple
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Blog extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('BlogModel');
$this->load->library('table');
}
public function index($offset=0)
{
$config['base_url'] = site_url('blog/index');
$config["total_rows"] = $this->BlogModel->get_Count(); // There are currently 36 Posts
$config["per_page"] = 5; // Change limit to suit what you would like
$config['num_links'] = 10;
/*use this code for bootstrap
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a class="">';
$config['cur_tag_close'] = '</a></li>';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '<li>';
$config['next_tag_open'] = '<li class="next">';
$config['next_tag_close'] = '</li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['first_link'] = '<<';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_link'] = '>>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
*/
$this->pagination->initialize($config);
$data['blog_pagination'] = $this->pagination->create_links();
$data['posts'] = $this->BlogModel->get_Posts($config['per_page'],$this->uri->segment(3));
$this->load->view('header');
$this->load->view('blog', $data);
$this->load->view('footer');
}
}
i have created pagination with codeigniter 3.
On every page i am getting same results:
my final url seems like: http://localhost/shoping/products/mobile-phones?cid=3&page=2
Controller file:
public function category(){
$category_id = $this->input->get('cid', TRUE);
$slug = $this->uri->segment(2);
$sortby = $this->input->get('sort', TRUE);
$sorttype= 'ASC';
$limit = 10;
$config = array();
$config['base_url'] = base_url() . 'products/'.$slug.'?cid='.$category_id;
$config['total_rows'] = $this->Product_model->category_product_count($category_id);
$config['per_page'] = $limit;
$config['use_page_numbers'] = TRUE;
$config['page_query_string'] = TRUE;
$config['query_string_segment'] = 'page';
// $config["uri_segment"] = 3;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['prev_link'] = '«';
$config['next_link'] = '»';
$config['cur_tag_open'] = '<li><a class="current">';
$config['cur_tag_close'] = '</a></li>';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$choice = $config["total_rows"] / $config["per_page"];
$config["num_links"] = round($choice);
$this->pagination->initialize($config);
if($this->uri->segment(2) > 0){
$page = ($this->uri->segment(2) + 0)*$config['per_page'] - $config['per_page'];
}
else{
$page = $this->uri->segment(2);
}
$data["links"] = $this->pagination->create_links();
if($data["links"]!= '') {
$data['pagermessage'] = 'Showing '.((($this->pagination->cur_page-1)*$this->pagination->per_page)+1).' to '.($this->pagination->cur_page*$this->pagination->per_page).' of '.$config['total_rows'];
}
if($this->input->get('sort')=='pricelow'){
$sortby = 'price';
$sorttype= 'ASC';
}
elseif($this->input->get('sort')=='pricehigh'){
$sortby = 'price';
$sorttype= 'DESC';
}
elseif($this->input->get('sort')=='new'){
$sortby = 'updated_on';
$sorttype= 'DESC';
}
elseif($this->input->get('sort')=='popularity'){
$sortby = 'price';
$sorttype= 'DESC';
}
else{
$sortby = 'title';
$sorttype= 'ASC';
}
//Get all products
$data['products_by_category'] = $this->Product_model->get_products_by_category($category_id, $config["per_page"], $page, $sortby, $sorttype);
// echo $config['total_rows'];
// Load View
$data['main_content'] = 'public/products_category';
$this->load->view('public/layouts/home_main', $data);
}
Model File:
public function get_products_by_category($category_id, $limit, $start='', $shortby='', $shorttype=''){
$this->db->select('*');
$this->db->where('category_id', $category_id);
$this->db->limit($limit, $start);
$this->db->order_by($shortby, $shorttype);
$query = $this->db->get('products');
if($query->num_rows() > 0){
return $query->result();
}else{
return false;
}
}
and view file:
<?php foreach($products_by_category as $product): ?>
<div class="col-sm-4 col-md-4 col-lg-3">
<div class="single-product" style="height:300px;margin-bottom:10px">
<span class="sale-on">sale</span>
<div class="product-image">
<div class="show-img">
<a href="<?php echo base_url();?><?php echo $product->slug.'?sid='.$product->id;?>">
<img src="<?php echo base_url(); ?>assets/images/products/<?php echo $product->image;?>" alt="<?php echo $product->title;?>" height="150" width="150">
</a>
</div>
</div>
<div class="prod-info">
<h2 class="pro-name">
<?php echo $product->title.$product->id;?>
</h2><br>
<div class="price-box">
<div class="price">
<span><i class="fa fa-inr"></i><?php echo $product->price;?></span>
</div>
<div class="old-price">
<span><i class="fa fa-inr"></i><?php echo $product->mrp_price;?></span>
</div>
</div>
<div class="actions">
<span class="new-pro-wish">
<i class="fa fa-heart-o"></i>
</span>
<span class="new-pro-compaire">
<i class="fa fa-bar-chart"></i>
</span>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
Instead of $this->uri->segment(2), use $this->input->get('page', TRUE).
See CI_Input::get for more information on how you can get query string variables.
img
Every time I add a second comment, my post is duplicated. This appeared when I included comments in the system.
My code is below. Posts are duplicated every time I add a new comment.
1 comment = 1 post; 2 comments = 2 post; 3 comments = 3 post[...]
My Controller:
public function index()
{
if($this->session->userdata('u_logged') == TRUE)
{
$config = array();
$config['base_url'] = base_url().'core/index';
$config['total_rows'] = $this->core_model->types_count();
$config['per_page'] = 4;
$config['uri_segment'] = 3;
$config['use_page_numbers'] = TRUE;
$config['full_tag_open'] = "<ul class='pagination noborder'>";
$config['full_tag_close'] ="</ul>";
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = "<li class='disabled noborder'><li class='active noborder'><a href='#'>";
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
$config['next_tag_open'] = "<li>";
$config['next_tagl_close'] = "</li>";
$config['prev_tag_open'] = "<li>";
$config['prev_tagl_close'] = "</li>";
$config['first_tag_open'] = "<li>";
$config['first_tagl_close'] = "</li>";
$config['last_tag_open'] = "<li>";
$config['last_tagl_close'] = "</li>";
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data['results'] = $this->core_model->fetchTypes($config['per_page'], $page);
$data['links'] = $this->pagination->create_links();
$data['notifications'] = $this->core_model->getLastNotifications();
$this->loadTemplate('pages', 'index_view', $data);
if(!empty($this->input->post('comm')))
{
$this->core_model->addComment();
}
}
else if($this->session->userdata('u_logged') == FALSE)
{
$this->loadTemplate('pages', 'index_view', '0');
}
}
My Model
public function types_count()
{
return $this->db->count_all('types');
}
public function fetchTypes($limit, $start)
{
$this->db->limit($limit, $start);
$this->db->order_by('t_id', 'DESC');
$this->db->from('types');
$this->db->join('comments', 'comments.c_type_id = types.t_id');
$query = $this->db->get();
if($query->num_rows() > 0)
{
foreach($query->result() as $row)
{
$data[] = $row;
}
return $data;
}
return false;
}
public function addComment()
{
$text = $this->input->post('inputComment');
$authorid = $this->session->userdata('u_id');
$typeid = $this->input->post('t_id');
$this->db->select('c_date');
$this->db->where('c_author', $authorid);
$query = $this->db->get('comments');
$data = $query->result();
if($query->num_rows() > 0)
{
if($data[0]->c_date - time() < -120)
{
$data = array(
'c_author' => $authorid,
'c_date' => time(),
'c_show' => '1',
'c_text' => $text,
'c_type_id' => $typeid
);
$this->db->insert('comments', $data);
}
else
{
echo 'poczekaj';
}
}
else
{
$data = array(
'c_author' => $authorid,
'c_date' => time(),
'c_show' => '1',
'c_text' => $text,
'c_type_id' => $typeid
);
$this->db->insert('comments', $data);
}
}
**And the view**
<?php foreach($results as $type) { ?>
<div class="panel panel-default noborder">
<div class="panel-body">
<div class="media noboder">
<div class="media-left">
<img class="media-object" style="width: 48px;" src="https://scontent-waw1-1.xx.fbcdn.net/v/t1.0-9/13413743_1729080443973113_1289643015497858641_n.jpg?oh=98e497c14d65c2102bd9a41777447937&oe=582E9E1E">
</div>
<div class="media-body">
<h4 class="media-heading"><strong>Rafał Chojnowski</strong><small class="pull-right"><?php if($type->t_type_for == '0') { echo 'TYP DARMOWY'; } else { echo 'TYP PREMIUM'; } ?></small></h4>
<small><?php echo mdate($dateString, $type->t_date); ?></small><br />
<p>
<?php echo $type->t_match.', liga '.$type->t_league.', typ '.$type->t_type.', rozpocznie się '.$type->t_start_date.'. Kurs: '.$type->t_course.' '.$type->t_comment; ?>
</p>
</div>
<hr>
<?php foreach($results as $comment) { ?>
<div class="media-left">
<img class="media-object" style="width: 32px;" src="https://scontent-waw1-1.xx.fbcdn.net/v/t1.0-9/13001028_1523205167987703_4311803603524761516_n.jpg?oh=fb2068c87060975ab7187cde7f1a161f&oe=57EA8DA5">
</div>
<div class="media-body">
<h6 class="media-heading"><strong>Tomasz Chwicewski</strong> <small><?php echo mdate($dateString, $comment->c_date); ?></small></h6>
<?php echo $comment->c_text; ?>
</div>
<br />
<?php } ?>
<?php $hidden = array('t_id' => $type->t_id, 'c_author' => $this->session->userdata('u_id'), 'comm' => '1'); ?>
<?php echo form_open('core/index', '', $hidden); ?>
<div class="input-group">
<input type="text" class="form-control input-sm noborder" name="inputComment" placeholder="Dodaj komentarz">
<span class="input-group-btn">
<button class="btn btn-primary btn-sm noborder" type="submit">Dodaj</button>
</span>
</div>
<?php echo form_close(); ?>
</div>
</div>
</div>
<?php } ?>
I am working on Codeigniter Pagination and following this link :
http://www.technicalkeeda.com/codeigniter-tutorials/pagination-using-php-codeigniter
but when i click on further links i.e. 1,2 and so on then the next sequence of records does not loads up only the initial (from 1 to 5 shows up) i have seen other links on stackoverflow : CodeIgniter Pagination Page Links Not Working but it did not work. My code is as follows, please help to solve my problem:
Controller: home.php
<?php
class Home extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('MovieModel');
$this->load->library('pagination');
}
public function index($offset=0){
$config['total_rows'] = $this->MovieModel->totalMovies();
$config['base_url'] = base_url().'/home/index';
$config['per_page'] = 5;
$config['uri_segment'] = '2';
$config['full_tag_open'] = '<div class="pagination"><ul>';
$config['full_tag_close'] = '</ul></div>';
$config['first_link'] = '« First';
$config['first_tag_open'] = '<li class="prev page">';
$config['first_tag_close'] = '</li>';
$config['last_link'] = 'Last »';
$config['last_tag_open'] = '<li class="next page">';
$config['last_tag_close'] = '</li>';
$config['next_link'] = 'Next →';
$config['next_tag_open'] = '<li class="next page">';
$config['next_tag_close'] = '</li>';
$config['prev_link'] = '← Previous';
$config['prev_tag_open'] = '<li class="prev page">';
$config['prev_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li class="page">';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$query = $this->MovieModel->getMovies(5,$this->uri->segment(2));
$data['MOVIES'] = null;
if($query){
$data['MOVIES'] = $query;
}
$this->load->view('index1.php', $data);
}
}
?>
MovieModel.php
<?php
class MovieModel extends CI_Model {
function getMovies($limit=null,$offset=NULL){
$this->db->select("MOVIE_ID,FILM_NAME,DIRECTOR,RELEASE_YEAR");
$this->db->from('trn_movies');
$this->db->limit($limit, $offset);
$query = $this->db->get();
return $query->result();
}
function totalMovies(){
return $this->db->count_all_results('trn_movies');
}
}
?>
View: index1.php
<!DOCTYPE html>
<html lang="en">
<head>
<title>Codeigniter Pagination Example</title>
<link href="<?= base_url();?>css/bootstrap.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="row">
<h4>Movies List</h4>
<table class="table table-striped table-bordered table-condensed">
<tr><td><strong>Movie Id</strong></td><td><strong>Film Name</strong></td><td><strong>Director</strong></td><td><strong>Release Year</strong></td></tr>
<?php
if(is_array($MOVIES) && count($MOVIES) ) {
foreach($MOVIES as $movie){
?>
<tr><td><?=$movie->MOVIE_ID;?></td><td><?=$movie->FILM_NAME;?></td><td><?=$movie->DIRECTOR;?></td><td><?=$movie->RELEASE_YEAR;?></td></tr>
<?php
}
}?>
</table>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="row"><?php echo $this->pagination->create_links(); ?></div>
</div>
</div>
</div>
</body>
</html>
Use the below coding
if($this->uri->segment(3))
$offset = $this->uri->segment(3);
else
$offset = 0;
$query = $this->MovieModel->getMovies(5,$offset);
I build a catalog website. The catalog location is in http://localhost/bookstore/site/catalog. Then if i click one of book the url change to http://localhost/bookstore/site/detail/100016 and it show the detail of book.
And now i click the pagination, the url change to http://localhost/bookstore/site/catalog/12, its work fine. But if i click one of book, its doesnt show detail of book because the url change to http://localhost/bookstore/site/catalog/detail/100005.
Can you see what different? yes, the url still save method catalog so detail of book cant be shown. What should i do?
This my controller
public function catalog()
{
$config['full_tag_open'] = '<div class="pagination pagination-colory"><ul>';
$config['full_tag_close'] = '</ul></div>';
$config['first_link'] = '« First';
$config['first_tag_open'] = '<li class="prev page">';
$config['first_tag_close'] = '</li>';
$config['last_link'] = 'Last »';
$config['last_tag_open'] = '<li class="next page">';
$config['last_tag_close'] = '</li>';
$config['next_link'] = 'Next →';
$config['next_tag_open'] = '<li class="next page">';
$config['next_tag_close'] = '</li>';
$config['prev_link'] = '← Previous';
$config['prev_tag_open'] = '<li class="prev page">';
$config['prev_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li class="page">';
$config['num_tag_close'] = '</li>';
$config['base_url'] = base_url('site/catalog');
$config['total_rows'] = $this->db->get('buku')->num_rows();
$config['per_page'] = 12;
//$config['uri_segment'] = 3;
$dari = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data['databuku'] = $this->m_site->show_buku($config['per_page'],$dari);
$this->pagination->initialize($config);
$this->load->view('v_catalog_buku', $data);
}
Model
function show_buku($limit, $offset)
{
$this->db->order_by("id_buku", "desc");
$query = $this->db->get("buku", $limit, $offset);
return $query->result();
}
View
<table>
<div class="row">
<?php foreach($databuku as $row ):?>
<a href="<?php base_url(); ?>detail/<?php echo $row->id_buku; ?>"><div class="span3" style="height:450px;" >
<div class="icons-box">
<div class="row" style="height:100px;">
<div class="body"><h3><?php echo $row->judul; ?></h3></div>
</div>
<div class="row" style="height:200px;">
<img src="<?php echo base_url('uploads/'.$row->img);?>" height="120px" width="120px"/>
</div>
<div class="row">
<div><h3>Rp.<?php echo number_format($row->harga,2,",",".");?></h3></div>
</div>
</div>
</div></a>
<?php endforeach; ?>
</div>
</table>
<div class="box-content" align="center">
<?php echo $this->pagination->create_links(); ?>
</div>
<!-- end: Row -->
</div>