Welcome Guest, Not a member yet? Register   Sign In
Pagination for my query
#1

[eluser]ThatsJustMe[/eluser]
Hello,

So basically I have a helper and it's code is -

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if (!function_exists('records'))
{
    function records()
    {        
      $ci = get_instance();                    
      $ci->db->order_by("date", "desc");
      $ci->db->limit(20);
      $query = $ci->db->join('records', 'users.id=records.user_id')->get('users');
      $data =array();
      foreach($query->result_array() as $orders)
      {
         $data[] = $orders;
      }            
      return $data;
    }  
}

?>

Now I need to add a pagination for it, so there is only 5 rows per page. I tried to add pagination library and echoed it out, but it gives me 3 pages, which doesn't work. Code -

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if (!function_exists('records'))
{
    function records()
    {        
      $ci = get_instance();                    
      $ci->db->order_by("date", "desc");
      $ci->db->limit(20);
      $query = $ci->db->join('records', 'users.id=records.user_id')->get('users');
      $data =array();
      foreach($query->result_array() as $orders)
      {
         $data[] = $orders;
      }            
   $ci->load->library('pagination');

      $config['base_url'] = 'http://localhost/savieno/records/';
      $config['total_rows'] = 20;
      $config['per_page'] = 5;
      
      $ci->pagination->initialize($config);
      
      echo $ci->pagination->create_links();      
      return $data;
    }  
}

?>

Any suggestions?
#2

[eluser]ThatsJustMe[/eluser]
bump!
#3

[eluser]BrokenLegGuy[/eluser]
http://ellislab.com/forums/viewthread/135509/




Theme © iAndrew 2016 - Forum software by © MyBB