[eluser]haris244808[/eluser]
ok dudes...i still didnt manage this pagination...
It works ok but when i click the 2nd , 3rd ... buttons it gets the segment number in the url but it show me the Erorr 404: Page not found
can you please help me achieve this..??
Here is my final code:
Controller:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->library('pagination');
$this->load->model('files_model');
$this->output->enable_profiler(TRUE);
}
function index(){
$data['page_title'] = 'Home Page'; //define the page title to be displayed
$data['content'] = 'home_view'; //assign login_form to $content variable of template
$data = array_merge($data, $this->files_pagination());
$this->load->view('includes/template', $data); //pass the data to the include/template.php and load it
}
function files_pagination(){
$config['base_url'] = site_url('home');
$config['total_rows'] = $this->files_model->count_all_files();
$config['per_page'] = 2; //records to be displayed per page
$config['num_links'] = 10; //how many page numbers to be shown between previous and next
$config['uri_segment'] = 2;
//$config['use_page_numbers'] = TRUE;
$this->pagination->initialize($config);
$offset = ($this->uri->segment(3)) ? $this->uri->segment(2) : 0;
$data['files_query'] = $this->files_model->show_files($config['per_page'], $offset);
$data['page_links'] = $this->pagination->create_links();
return $data;
}
}//end Site class
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Files_model extends CI_Model
{
function __construct()
{
parent::__construct();
}
function show_files($limit, $offset){
$sql = "SELECT users.first_name, users.last_name, files.* FROM users INNER JOIN files ON users.id = files.user_id WHERE user_id = ? LIMIT ?, ?";
$files_query = $this->db->query($sql, array($this->session->userdata('id'), $limit, $offset));
if ($files_query->num_rows() > 0) {
return $files_query->result();
}
return false;
}
function count_all_files(){
$this->db->select('users.first_name, users.last_name, files.*');
$this->db->from('users');
$this->db->join('files', 'users.id = files.user_id');
$this->db->where('user_id', $this->session->userdata('id'));
return $this->db->count_all_results();
}
} //end of File_model class