Welcome Guest, Not a member yet? Register   Sign In
Pagination, a simple thing but stuck [RESOLVED]
#1

[eluser]minutes2memories[/eluser]
hi folks,

i'm admittedly new to CI (a week!) but all gone well to date, until i've tried to get pagination happening.

i have a subscriber database with search interface where i want the user to be able to edit and delete entries and return to the last viewed page of their most recent search when they've done their editing. to do this i'm storing some stuff in a CI session at the time of the search and then i wish to use that in the same controller, different method, to show the most recent search (with pagination).

so i store this stuff to populate the search query in one method:

Code:
$last_search = array('search_term'=> $data['search_term'], 'search_field'=> $data['search_field'], 'total_rows'=> $data['total_rows']);
$this->session->set_userdata($last_search);

and then do a simple search:

Code:
// prepare and perform our query
$data['search_term'] = $this->session->userdata['search_term'];
$data['search_field'] = $this->session->userdata['search_field'];
            
$query = $this->subscribers_db->admin_search($data['search_term'], $data['search_field'], $num_rows, $offset);
$this->data['subscriber_list'] = $query->result();

now i'm hoping to populate $offset (for my sql offset) with a value passed via the pagination links. that is, 10, 20, 30 etc (10 per page) and here is my pagination attempt in the same method:

Code:
$this->load->library('pagination');

$config['base_url'] = '/subscribers/view/';
$config['total_rows'] = $this->session->userdata['total_rows'];
$config['uri_segment'] = 3; // try to use 3rd segment to pass offset? andrewg.
$config['per_page'] = $num_rows;
    
$this->pagination->initialize($config);

where i was hoping (dreaming?) to populate the 3rd uri segment ($offset passed to this method) from the pagination link (eg. example.com/subscribers/view/10). but what i get as the pagination link is:

/subscribers/view/&per_page=10
/subscribers/view/&per_page=20 and so on

i'm sorry if this is really really stupid. am sure it is, but i've gotten to complete brain freeze reading tutes and the user guide stuff over and again. appreciate any pointers really.

thanks,
andrewg.
#2

[eluser]minutes2memories[/eluser]
SOLVED Smile

as i thought, i was just being a bit dim....
Code:
$config['base_url'] = '/subscribers/view?'; // trailling ? for $_GET parameter
$config['query_string_segment'] = 'offset';

enabled me to specify that the parameter passed was my offset value. i could then pick it up in my search and return the relevant data using my num per page limit and my offset.

maybe this will help someone else on a bad day.

btw, CI does rock.

andrewg.




Theme © iAndrew 2016 - Forum software by © MyBB