Welcome Guest, Not a member yet? Register   Sign In
Save query in pagination
#1

[eluser]nofearinc[/eluser]
I have a search form that queries few tables and extracts a result set which is paginated. The problem is that when I click on another page, query gets clear (select *) and no search data is applied anymore. My search parameters are not persistent after the first request.

How can I save the search criteria when switching through paginated table?

P.S. Similar problem without replies: second link doesn't save the query
#2

[eluser]Colin Williams[/eluser]
Code?
#3

[eluser]nofearinc[/eluser]
It's 20 parameters from 6 joined tables, but the important part is that I generate query with $_POST parameters and logically they aren't persistent during paging.

Code:
function sell() {
    $per_page = 10;
    $base_url = site_url('results/sell');
    $config['uri_segment'] = 3;
    
    $query = $this->offers->get_all_sell($per_page,
        $this->uri->segment($config['uri_segment']),
        ...
        $this->input->post('min_area'),
        $this->input->post('max_area'),
        $this->input->post('min_price'),
        $this->input->post('max_price'),  
        $this->input->post('min_category'),
        $this->input->post('max_category'),
        ...);
                            
    $config['base_url'] = site_url('results/sell');
    $config['total_rows'] = $this->offers->get_sell_count(
                                        ...
                                        $this->input->post('min_area'),
                                        $this->input->post('max_area'),
                                        $this->input->post('min_price'),
                                        $this->input->post('max_price'),  
                                        $this->input->post('min_category'),
                                        $this->input->post('max_category'),
                                        ...);
    $config['per_page'] = $per_page;
    
    $this->pagination->initialize($config);

    $data['pagination'] = $this->pagination->create_links();
    $data['offers'] = $query->result();
    
    $data['contentFile'] = "results/sell_view.php";
    $this->load->view("/template", $data);
}
#4

[eluser]nofearinc[/eluser]
A possible solution is saving input parameters into session and getting them from there every time I use pagination. The problem is when I'm going to flush the session?

The best way is repopulating the $_POST every time I click next page, but I'm not sure how can I do request forwarding here. Any ideas?
#5

[eluser]flaky[/eluser]
Have you considered flashdata ?
http://ellislab.com/codeigniter/user-gui...sions.html


Quote:Flashdata

CodeIgniter supports "flashdata", or session data that will only be available for the next server request, and are then automatically cleared. These can be very useful, and are typically used for informational or status messages (for example: "record 2 deleted").

Note: Flash variables are prefaced with "flash_" so avoid this prefix in your own session names.

To add flashdata:

Code:
$this->session->set_flashdata('item', 'value');

You can also pass an array to set_flashdata(), in the same manner as set_userdata().

To read a flashdata variable:

Code:
$this->session->flashdata('item');

If you find that you need to preserve a flashdata variable through an additional request, you can do so using the keep_flashdata() function.

Code:
$this->session->keep_flashdata('item');
#6

[eluser]nofearinc[/eluser]
It jumped out of my head, yes. That seems a good workaround of my problem, thanks. Going to test it this night.
#7

[eluser]nofearinc[/eluser]
Flashdata works just fine - before every page I send search parameters via session->set_flashdata(...) and retrieve them on load. One important detail only: If I try to directly use the session->flashdata() elements, I have strange caching for the first page load and it gets OK on refresh. I inspected it with the profiler and parameters haven't been sent to the query at all. Instead of refreshing, I assigned the flashdata() parameters to variables and that thing did the stuff.

Thanks for helping!




Theme © iAndrew 2016 - Forum software by © MyBB