CodeIgniter Forums
pagination links doesn't work - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: pagination links doesn't work (/thread-54490.html)



pagination links doesn't work - El Forum - 09-11-2012

[eluser]Unknown[/eluser]
English is not my native language.
I have a catalog of films and the code below, it works normally, except when I need to use special characters like accents and non-alphanumeric. For example: Paul Newman, is encoded as + Paul Newman and no results are found.
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Filmes extends CI_Controller
{

public function __construct()
{
        parent::__construct();
  $this->load->model("rel");
        $this->load->model("filmes");  
    
    }

public function index()
{

$this->load->view('movies/filmes);

}

function search($search_terms = '', $start = 0)
{
   if ($this->input->post('))
  {
   redirect('/ci/filmes/search/' . $this->input->post(', TRUE));
  }
  
  if ($search_terms)
  {
   // Determine the number of results to display per page
   $results_ = $this->config->item('results_');
  
  
  
   // Load the model, perform the search and establish the total
   // number of results
  
   $results = $this->filmes->search($search_terms, $start, $results_);
   $total_results = $this->filmes->count_search_results($search_terms);
  
    
   // Call a method to setup pagination
   $this->_setup_pagination('/ci/filmes/search/' . $search_terms . '/', $total_results, $results_);
  
   // Work out which results are being displayed
   $first_result = $start + 1;
   $last_result = min($start + $results_, $total_results);
  }
  
  // Render the view, passing it the necessary data
  $this->load->view('movies/search_results', array(
  
   'search_terms' => $search_terms,
   'first_result' => @$first_result,
   'last_result' => @$last_result,
   'total_results' => @$total_results,
   'results' => @$results
  ));
  
  }

function _setup_pagination($url, $total_results, $results_)
{
  
  
  // This is messy. I'm not sure why the pagination class can't work
  // this out itself...
  
  
  $uri = count(explode('/',$url));
  
  // Initialise the pagination class, passing in some minimum parameters
   $this->pagination->initialize(array(
   'base_url' => base_url($url),
   'uri' => 4,
   ' => $total_results,
   ' => $results_
  ));
}

function titles()
{

$this->load->view('movies/movie_results');

}

  public function lista() {
        $config = array();
        $config["base_url"] = base_url() . "/ci/filmes/lista";
        $config["total_rows"] = $this->rel->record_count();
        $config["per_page"] = 20;
        $config["uri"] = 3;

        $this->pagination->initialize($config);

        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data["results"] = $this->rel->
            fetch_titles($config["per_page"], $page);
        $data["links"] = $this->pagination->create_links();
        $this->load->view("movies/relfilmes", $data);
    }

  
}




/* End of file filmes_controller.php */
/* Location: ./application/controllers/filmes_controller.php */

I decided to change the code, but once again came back to have problems. Special characters are accepted, but when the number of results is greater than 5, the following links list the entire contents of db. For example: Clint Eastwood, has 12 results informed the number of links is 3, but from the link 2 the result is all the content of db.

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

class Filmes extends CI_Controller
{

public function __construct()
{
        parent::__construct();
  $this->load->model("rel");
        $this->load->model("filmes");  
    
    }

public function index()
{

$this->load->view('movies/filmes);

}

function search($start = 0)
{

  $search_terms = $this->input->post(');
  $config['base_url'] = '/ci/filmes/search/';
  $config['] = 5;
  $config['num_links'] = 5;
  $config['] = $this->filmes->count_search_results($search_terms);  
  $results = $this->filmes->search($search_terms, $start, $config[']);
  $total_results = $this->filmes->count_search_results($search_terms);
  $config['links'] = '/ci/filmes/search'.$search_terms.'';
    
  $this->pagination->initialize($config);
  $data = array(
  'search_terms' => $search_terms,
  'results' => $results,
  'total_results' => $total_results,
  $config['], $this->uri->segment(3));
  $this->load->view('movies/search_results', $data);  
}

  
function titles()
{

$this->load->view('movies/movie_results');

}

  public function lista()
  {
        $config = array();
        $config["base_url"] = '/ci/filmes/search/';
        $config["total_rows"] = $this->rel->record_count();
        $config["per_page"] = 20;
        $config["uri"] = 3;

        $this->pagination->initialize($config);

        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data["results"] = $this->rel->
            fetch_titles($config["per_page"], $page);
        $data["links"] = $this->pagination->create_links();
        $this->load->view("movies/relfilmes", $data);
    }

  
}

I appreciate any help in advance.