Welcome Guest, Not a member yet? Register   Sign In
Pagination Problem
#11

[eluser]haris244808[/eluser]
[quote author="TheFuzzy0ne" date="1363077001"]That's because you're not assigning the return value of files_pagination() to a variable, and then passing it into a view.[/quote]

but how should i return an array:

I tried to assign it to a variable and then return it:
Code:
$data['links'] = $this->pagination->create_links();

  $links = $data['links']

  return $links;

but it shows this error:
syntax error, unexpected T_RETURN in C:\xamp....
#12

[eluser]TheFuzzy0ne[/eluser]
That's not quite what I meant.

Code:
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

  $this->load->model('files_model');
  $data['files_query'] = $this->files_model->select_files_based_on_user();

// Something like this.
  $data = array_merge($data, $this->files_pagination());
// Without it, you're pagination links don't make it into the view.

  $this->load->view('includes/template', $data); //pass the data to the include/template.php and load it
}
#13

[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
#14

[eluser]haris244808[/eluser]
I solved it thnx for help Smile




Theme © iAndrew 2016 - Forum software by © MyBB