• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can you check my pagination?[SOLVED]

#1
Hello here is my issue, mi pagination has the url working fine, and I can see the pagination class insisde m view, but I still do not know how to retrieve just the number of entries that I want:

Here is my controller(News, function blog):

PHP Code:
       public function blog() {
         
       $data['blog'] = $this->blog_model->get_blog();
                
$data['categorias'] = $this->categorias_model->get_categorias();
                
$data['title'] = 'Blog';
        
        
                
$config = array();
                
$config["base_url"] = base_url() . "blog";
                
$config["total_rows"] = $this->blog_model->record_count();
                
$config["per_page"] = 1;
                
$config["uri_segment"] = 3;
                
$config['num_links'] = 1;
                
$config['query_string_segment'] = 'paginas';
                
$config['page_query_string'] = TRUE;
                
$config['display_pages'] = FALSE;
                
            
                
$this->pagination->initialize($config);
            
                
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
                
$data["pagination"] = $this->pagination->create_links();
                
$data["results"] = $this->blog_model->get_paginas($config["per_page"], $page);
                
                
$this->load->view('templates/head',$data);
                
$this->load->view('templates/navbar',$data);
                
$this->load->view("news/blog/index"$data);
                
$this->load->view('templates/footer',$data);


Here is my model(Blog_model):

PHP Code:
    class Blog_model extends CI_Model{
        
// Connect to database //
        
public function __construct(){
            
$this->load->database();
            }
            
        
// Get Posts from database //
        
public function get_blog($slug=FALSE){
            if(
$slug===FALSE){
                
// Post order, ASC-DESC Categorias/Tags tabels //
                
$this->db->order_by('blog.id''DESC');
//                $this->db->join('categorias','categorias.id = blog.categoria_id');
                // /Post order, ASC-DESC //
                
$query=$this->db->get('blog');
                return 
$query->result_array();
                }
                
                
$query=$this->db->get_where('blog', array('slug'=>$slug));
                return 
$query->row_array();
            }
            
///Pagination
 
   public function record_count() {
 
   return $this->db->count_all("blog");
}

public function 
get_paginas($limit$start) {
 
   $this->db->limit($limit$start);
 
   $query $this->db->get("blog");

 
   if ($query->num_rows() > 0) {
 
       foreach ($query->result() as $row) {
 
           $data[] = $row;
 
       }
 
       return $data;
 
   }
 
   return false;
}


        
        
// Crear post //
        
public function crear_post(){
            
$slug=url_title($this->input->post('titulo'));
            
            
$data = array(
                
'titulo' => $this->input->post('titulo'),
                
'slug' => $slug,
                
'imagen' => $this->input->post('imagen'),
//                'autor' => $this->input->post('autor'),
                
'fecha' => $this->input->post('fecha'),
                
'contenido' => $this->input->post('contenido'),
                
'categoria_id' => $this->input->post('categoria_id'),

            );
            
            return 
$this->db->insert('blog',$data);
            
            }
            
        
// Borrar post //    
            
public function delete_post($id){
            
$this->db->where('id'$id);
            
$this->db->delete('blog');
            return 
true;
        }
        
// Actualizar Post //
        
public function update_post(){
            
$slug url_title($this->input->post('titulo'));
            
$data = array(
                
'titulo' => $this->input->post('titulo'),
                
'slug' => $slug,
                
'imagen' => $this->input->post('imagen'),
//                'autor' => $this->input->post('autor'),
                
'fecha' => $this->input->post('fecha'),
                
'contenido' => $this->input->post('contenido'),
                
'categoria_id' => $this->input->post('categoria_id'),

            );
            
$this->db->where('id'$this->input->post('id'));
            return 
$this->db->update('blog'$data);
        }

        
// Categorias //
        
//        public function get_categorias(){
//            $this->db->order_by('nombre');
//            $query = $this->db->get('categorias');
//            return $query->result_array();
//        }
            

        
        


Here is my view(views/news/blog/index):
Code:
<nav class="breadcrumb">
    <div class="container">
     <a class="breadcrumb-item" id="a" href="<?php echo base_url(); ?>">Home</a>
     <span class="breadcrumb-item active">Blog</span>
   </div>
</nav>

<div class="container" id="main">
<div class="row">
<!-- Article -->
<div class="col-md-8 animated fadeIn">
<?php foreach($blog as $blog) : ?>
<div class="card text-xs-left"><!-- FIRST ARTICLE DEMO -->
<div class="card-header" id="article-header">
<h4><a href="<?php echo site_url('/blog/'.$blog['slug']); ?>"><?php echo ucfirst($blog['titulo']); ?></a></h4>
</div>
<img src="<?php echo $blog['imagen']; ?>" width="750" heihgt="350" class="img-fluid">
<!--<div class="card-body">
<p> <?php  echo word_limiter($blog['contenido'],5); ?></p>
</div>-->
<div class="card-footer" id="article-footer">
<div class="row">
<div class="col-lg-12 col-md-9 col-sm-8">
<i class="fa fa-calendar" aria-hidden="true"></i> <?php echo ucfirst($blog['fecha']); ?>

<i class="fa fa-folder" aria-hidden="true"></i> <?php echo $blog['categoria_id']; ?>

<a href="<?php echo site_url('/blog/'.$blog['slug']); ?>" class="pull-right">Read more »</a>
</div>
</div>
</div>
</div>
<?php endforeach ?>
<!-- /Article -->
<?php echo $pagination ?>
</div>

<div class="col-md-4 animated fadeIn">
<!-- Search -->
<form class="form-inline-fluid">
<input class="form-control" type="text" placeholder="Search">
<button type="submit" class="btn btn-success" style="border-radius: 0;position: absolute;z-index: 99;top: 0;right: 1rem;"><i class="fa fa-search" aria-hidden="true"></i></button>
</form>
<!-- Categorias -->
<hr>
<div class="list-group" id="">
<a href="" class="list-group-item active" id="dashboard-active"><i class="fa fa-tachometer" aria-hidden="true"></i> Categorias</a>
<?php foreach ($categorias as $blog) : ?>
<a class="list-group-item list-group-item-action" href="#" role="button"><i class="fa fa-folder" aria-hidden="true"></i> <?php echo $blog['nombre']; ?></a>
<?php endforeach ?>
</div>
<hr>Tiempo en cargar <strong>{elapsed_time}</strong><hr>
<!-- Social media tabs -->
<br>
<h5>Social Media</h5>
<ul class="nav nav-tabs" role="tablist" id="tablist">
<li class="nav-item" id="social-tabs">
<a class="nav-link btn btn-danger active" id="social-facebook" data-toggle="tab" href="#facebook" role="tab" aria-expanded="true">Facebook</a>
</li>
<li class="nav-item" id="social-tabs">
<a class="nav-link btn btn-danger" id="social-twitter" data-toggle="tab" href="#twitter" role="tab" aria-expanded="false">Twitter</a>
</li>
</ul>
<!-- Social media content -->
<div class="tab-content" id="tab-content">
<!-- Facebok -->
<div class="tab-pane active" id="facebook" role="tabpanel" aria-expanded="true">
<div class="tags">
<div class="panel">
<div class="tab-pane" id="Facebook">
<div class="fb-page" data-href="https://www.facebook.com/blogpersonal.net" data-tabs="timeline" data-height="500" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="true"></div>
</div>
</div>
</div>
</div>
<!-- /Facebok -->
<!-- Twitter -->
<div class="tab-pane" id="twitter" role="tabpanel" aria-expanded="false"><!-- Twitter -->
<a class="twitter-timeline" href="https://twitter.com/kirasiris" data-chrome="noheader nofooter noborders "  data-tweet-limit="3">Tweets by @Kirasiris</a>
</div>
<!-- /Twitter -->
</div>
<hr>
</div>
</div>
</div>

eveytime that hit the next button, last button, first button, previous button , it shows me alll the entries that I have on database, any suggestion?

Here is my route file:
PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');
//* Admin Pages *//  Can be found in the admin controller
// Edit global pages ////
$route['admin/actualizarpagina_terms'] = 'admin/actualizarpagina_terms';
$route['admin/actualizarpagina_privacy'] = 'admin/actualizarpagina_privacy';
$route['admin/actualizarpagina_cookies'] = 'admin/actualizarpagina_cookies';
$route['admin/actualizarpagina_about'] = 'admin/actualizarpagina_about';
$route['admin/actualizarskills'] = 'admin/actualizarskills';
$route['admin/actualizarcategory'] = 'admin/actualizarcategory';
$route['admin/crearcategory'] = 'admin/crearcategory';
$route['admin/categorias'] = 'admin/categorias';
$route['admin/crearpagina'] = 'admin/crearpagina';
$route['admin/crearpost'] = 'admin/crearpost';
$route['admin/crearskill'] = 'admin/crearskill';
$route['admin/crearportfolio'] = 'admin/crearportfolio';
$route['admin/actualizarpagina'] = 'admin/actualizarpagina';
$route['admin/actualizarpost'] = 'admin/actualizarpost';
$route['admin/actualizarportfolio'] = 'admin/actualizarportfolio';
$route['admin/paginas'] = 'admin/paginas';
$route['admin/posts'] = 'admin/posts';
$route['admin/portfolio'] = 'admin/portfolio';
$route['admin/skills'] = 'admin/skills';
$route['admin'] = 'admin/index';
$route['admin/(:any)'] = 'admin/view/$1';
//* Global pages *// Can be found in the news controller
$route['portfolio/(:any)'] = 'portfolio/view/$1';
$route['portfolio'] = 'news/portfolio/index';
$route['blog'] = 'news/blog/index';
$route['blog/(:any)'] = 'blog/view/$1';
$route['contact'] = 'news/contact';
$route['cookies'] = 'news/cookies';
$route['about'] = 'news/about';
$route['terms'] = 'news/terms';
$route['privacy'] = 'news/privacy';
$route['news'] = 'news';
$route['news/(:any)'] = 'news/view/$1';
//* Default *//
$route['default_controller'] = 'news';
$route['(:any)'] = 'pages/view/$1';
$route['404_override'] = '';
$route['translate_uri_dashes'] = TRUE
I do Front-End development most of the time 
Reply


Messages In This Thread
Can you check my pagination?[SOLVED] - by kirasiris - 02-08-2017, 06:47 PM
RE: Can you check my pagination? - by Wouter60 - 02-08-2017, 11:48 PM
RE: Can you check my pagination? - by kirasiris - 02-09-2017, 12:53 AM
RE: Can you check my pagination? - by Wouter60 - 02-09-2017, 05:42 AM
RE: Can you check my pagination? - by kirasiris - 02-09-2017, 06:12 AM
RE: Can you check my pagination? - by Wouter60 - 02-09-2017, 08:56 AM
RE: Can you check my pagination? - by kirasiris - 02-09-2017, 06:25 PM
RE: Can you check my pagination? - by Wouter60 - 02-09-2017, 11:40 PM
RE: Can you check my pagination? - by kirasiris - 02-10-2017, 12:50 PM
RE: Can you check my pagination? - by pdthinh - 02-10-2017, 10:01 PM
RE: Can you check my pagination? - by kirasiris - 02-10-2017, 10:46 PM
RE: Can you check my pagination? - by pdthinh - 02-10-2017, 11:14 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.