We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Codeigniter pagination help

Development and Programming

cnl1203ny's avatar
cnl1203ny
2 posts
11 years ago
cnl1203ny's avatar cnl1203ny

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!

       
Boyink!'s avatar
Boyink!
5,011 posts
11 years ago
Boyink!'s avatar Boyink!

You’ve posted in the ExpressionEngine forum.

       
radley7992's avatar
radley7992
1 posts
3 years ago
radley7992's avatar radley7992

I really like this post and how I love hearing their testimonies. Slope unblocked is a sport in which the green ball is manipulated. In the beginning, the ball moves slowly through the slopes. The speed gradually rises as you progress. To avoid losing contact with the 3D real environment, it is critical to be aware and quick to react.

       
otis's avatar
otis
7 posts
2 years ago
otis's avatar otis

Based on your description, pokemon infinite fusion it seems like you want to bypass the form and directly display the paginated results when a specific state value is hardcoded (e.g., “NY”).

       
minhee's avatar
minhee
1 posts
one year ago
minhee's avatar minhee

Hey there! Welcome to the CodeIgniter community! I’m definitely not a pro, but have you checked your base URL configuration? Pagination in CI can be tricky if it’s not set up correctly. https://cookieclickerfree.github.io/

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.