[eluser]Unknown[/eluser]
Good day everyone,
I am relatively new to code igniter and have a pressing issue with pagination. I have the following function:
public function view() {
$this->form_validation->set_rules(‘state’, ‘state’, ‘trim|required’);
if($this->form_validation->run() == FALSE) {
$this->load->view(‘view’);
} else {
$state = $this->input->post(‘state’);
// Setup the SELECT statement
$qry = “SELECT city, state, photo_url”;
$qry = $qry . ” FROM membership;
$qry = $qry . ” WHERE state = ‘“.$state.”’ ORDER BY state ASC, name ASC”;
// Set the limit and offset
$limit = 20;
$offset = ($this->uri->segment(3) != ‘’ ? $this->uri->segment(3) : 0);
// Setup the $config variables for pagination
$config[‘base_url’] = ‘http://www.somewebsite.com/ci/index.php/cr/view’;
$config[‘total_rows’] = $this->db->query($qry)->num_rows();
$config[‘uri_segment’] = 3;
$config[‘per_page’] = $limit;
$config[‘num_links’] = 10;
$config[‘full_tag_open’] = ‘<div id=“pagination”>’;
$config[‘full_tag_close’] = ‘</div>’;
// Initialize the $config
$this->pagination->initialize($config);
// Limit and get the data
$qry = $qry . ” LIMIT {$limit} OFFSET {$offset}”;
$data[‘result_per_page’] = $this->db->query($qry)->result();
// Now go and display the data
$this->load->view(‘people’, $data);
}
}
The code works great the first passage and it shows me the first 20 records of the database. However, when I click on the link for the next 20, it crashes and displays the form to enter the desired state.
Now, if I was to remove the lines below that have an * at the beginning of each line:
public function view() {
* $this->form_validation->set_rules(‘state’, ‘state’, ‘trim|required’);
* if($this->form_validation->run() == FALSE) {
* $this->load->view(‘view’);
* } else {
* $state = $this->input->post(‘state’);
// Setup the SELECT statement
$qry = “SELECT city, state, photo_url”;
$qry = $qry . ” FROM membership;
$qry = $qry . ” WHERE state = ‘“.$state.”’ ORDER BY state ASC, name ASC”;
// Set the limit and offset
$limit = 20;
$offset = ($this->uri->segment(3) != ‘’ ? $this->uri->segment(3) : 0);
// Setup the $config variables for pagination
$config[‘base_url’] = ‘http://www.somewebsite.com/ci/index.php/cr/view’;
$config[‘total_rows’] = $this->db->query($qry)->num_rows();
$config[‘uri_segment’] = 3;
$config[‘per_page’] = $limit;
$config[‘num_links’] = 10;
$config[‘full_tag_open’] = ‘<div id=“pagination”>’;
$config[‘full_tag_close’] = ‘</div>’;
// Initialize the $config
$this->pagination->initialize($config);
// Limit and get the data
$qry = $qry . ” LIMIT {$limit} OFFSET {$offset}”;
$data[‘result_per_page’] = $this->db->query($qry)->result();
// Now go and display the data
$this->load->view(‘people’, $data);
* }
}
and then hard code a line to select a certain state, i.e., ‘NY’, like the below code:
public function view() {
$state = ‘NY’;
// Setup the SELECT statement
$qry = “SELECT city, state, photo_url”;
$qry = $qry . ” FROM membership;
$qry = $qry . ” WHERE state = ‘“.$state.”’ ORDER BY state ASC, name ASC”;
// Set the limit and offset
$limit = 20;
$offset = ($this->uri->segment(3) != ‘’ ? $this->uri->segment(3) : 0);
// Setup the $config variables for pagination
$config[‘base_url’] = ‘http://www.somewebsite.com/ci/index.php/cr/view’;
$config[‘total_rows’] = $this->db->query($qry)->num_rows();
$config[‘uri_segment’] = 3;
$config[‘per_page’] = $limit;
$config[‘num_links’] = 10;
$config[‘full_tag_open’] = ‘<div id=“pagination”>’;
$config[‘full_tag_close’] = ‘</div>’;
// Initialize the $config
$this->pagination->initialize($config);
// Limit and get the data
$qry = $qry . ” LIMIT {$limit} OFFSET {$offset}”;
$data[‘result_per_page’] = $this->db->query($qry)->result();
// Now go and display the data
$this->load->view(‘people’, $data);
}
it works great and I can paginate through all the results. My question is:
How can I bypass the code for to not display the form again? I need to bypass the lines that have an * at the start of them. Is using isset the best way to do this? I am still trying to understand the isset function. I am new to all this so anyone’s help would greatly be appreciated!