Welcome Guest, Not a member yet? Register   Sign In
Pagination Alternatives?
#1

[eluser]CI_Newb[/eluser]
Well I'm giving up on using codeignter pagination for my search page.

The problem I'm having is that a user fills out the search form and submits it. It returns properly with the proper pagination.

Problem is that whenever a pagination link is clicked to go through the results, it's reloading the search page displaying all rows from the table like no search was done.

I've been searching for a solution but have yet to come up with anything so i'm looking into alternatives to using CI pagination.

Any suggestions?
#2

[eluser]Medikal[/eluser]
As advice I've been given, I'll pass it along since it worked for me.

The thought process behind pagination isn't difficult, you find say 10 results from a table if the page is the first page, if it's the second, you find results with an offset of 10, just a simple addition to your select query.

It's simple enough to make your own pagination system to work off of, just my 2 cents.
#3

[eluser]CI_Newb[/eluser]
Thanks for the advise Medikal, I hear what you're saying.

The main problem i'm guessing is that the search page is reloading which is just ignoring the search criteria. What I thought of doing to solve it was to have a hidden form that when a pagination link is clicked, it resubmits the hidden form that contains the search criteria.

Problem is I can't figure out how to make the pagination links able to submit the hidden form.
#4

[eluser]cartalot[/eluser]
this is a great video tutorial on pagination, and he shows how to set the offset etc for the db query
net.tutsplus.com/articles/news/codeigniter-from-scratch-day-7-pagination/
theres also a link for downloading the code
#5

[eluser]CI_Newb[/eluser]
[quote author="cartalot" date="1291014268"]this is a great video tutorial on pagination, and he shows how to set the offset etc for the db query
net.tutsplus.com/articles/news/codeigniter-from-scratch-day-7-pagination/
theres also a link for downloading the code[/quote]

I have seen that tutorial but it only goes into yanking all records from a table. Not using a search query.
#6

[eluser]Otemu[/eluser]
Hi,

Can you post your code so we can take a look.
#7

[eluser]CI_Newb[/eluser]
Model
Code:
function admin_search_total_rows()
    {
        $start_date = $this->input->post('startDate');    
        $end_date = $this->input->post('endDate');
        $username = $this->input->post('username');
        
        $dateRange = "submit_date BETWEEN '$start_date' and '$end_date'";
        $this->db->where($dateRange, NULL);
        $this->db->like('username', $username);

        $data = $this->db->get('data');
        
        if($data->num_rows() > 0) {
            return $data;
            }
    }


function admin_search($num, $offset)
    {
        $start_date = $this->input->post('startDate');    
        $end_date = $this->input->post('endDate');
        $username = $this->input->post('username');
        
        $dateRange = "submit_date BETWEEN '$start_date' and '$end_date'";
        $this->db->where($dateRange, NULL);
        $this->db->like('username', $username);

        $data = $this->db->get('data', $num, $offset);
        
        if($data->num_rows() > 0) {
            return $data;
            }
    }

Controller
Code:
function admin_results()
    {
        $this->load->library('pagination');

    $total = $this->search_model->admin_search_total_rows();
        
         $config['base_url'] = base_url().'/search/admin_results/';
        $config['total_rows'] = $total->num_rows();
        $config['per_page'] = '100';
        $config['num_links'] = 3;
        $config['full_tag_open'] = '<p>';
    $config['full_tag_close'] = '</p>';
    
    $this->pagination->initialize($config);
        
$criteria = array(
'hidden_startDate' => $this->input->post('startDate'),
'hidden_endDate' => $this->input->post('endDate'),
'hidden_stn' => $this->input->post('stn')
);
                
$this->session->set_flashdata($criteria);

        $data['users'] = $this->menus->agents_menu();
        $data['search'] = $this->search_model->admin_search($config['per_page'],$this->uri->segment(3));
        $this->load->view('content/header');
        $this->load->view('admin/admin_search_view', $data);
        $this->load->view('content/footer');
    }

View
Code:
&lt;form name="form_hidden" id="form_hidden" action="&lt;?php echo base_url();?&gt;search/admin_results" method="post"&gt;    
&lt;?php
echo form_hidden('startDate', set_value('startDate', $this->session->flashdata('hidden_startDate')));
echo form_hidden('endDate', set_value('endDate', $this->session->flashdata('hidden_endDate')));
?&gt;
<div>&lt;?php echo $this->pagination->create_links(); ?&gt;</div>
&lt;/form&gt;

As you can see in my latest attempt, I set the search criteria to flash_data but it really doesn't help getting it back into the query once the pagination links are clicked.
#8

[eluser]Atharva[/eluser]
I am not sure how are you 'posting' the values when user clicks on a pagination link, as clicking on link will make it a GET rather than POST. Second thing is, I don't see you are using flashdata which you set in controller. You must be using that flashdata in model instead of POST.
#9

[eluser]SitesByJoe[/eluser]
As mentioned above you can't store the persistent data you're passing as flashdata as it'll be wiped out after you next page load. With that approach you're better off using normal session variables.

I can also tell that you're still getting a grasp on what the pagination library really does. I'm sure it'll all click eventually.

I really like Joost's Pagination library Wiki Link as it frees up your url structure so you can use any uri segment you want. That would let you put the post data in your url if you want too so it's always available.




Theme © iAndrew 2016 - Forum software by © MyBB