Welcome Guest, Not a member yet? Register   Sign In
pagination with multiple search results (...i know...again)
#1

[eluser]Bartolo![/eluser]
Hi guys,

I've read a lot of posts but serious i dont see a solution for me. i'm sorry if there's one but most of them didn't suit my needs.

i read there are a couple of ways to make a pagination out of search results.

1. putting data in a session seems a little bit strange for me. that will mean that it remembers the data even when i come from a other page.

2. query chaching, sounds good but i don't know howto implement that into my page.

3. sending the search result together with the pagination result something like: index.php/customers/index/10/word/word/word

the last option is the one i think is the most interesting for me, but what if index.php/customers/index/10/word/word/word turns into index.php/customers/index/word/word/word ??

if anyone has a (simple) but effective solution for me i would really be happy :coolsmirk:

this is how i have it now:

controller;
Code:
#--------------------------------------------
    # INDEX
    #--------------------------------------------
    function index() {
        
        // pagination html
        $config['first_link'] =         'First';
        $config['last_link'] =          'Last';
        $config['next_link'] =          '>';
        $config['prev_link'] =          '<';
        $config['first_tag_open'] =     '<div>';
        $config['first_tag_close'] =    '</div>';
        $config['last_tag_open'] =      '<div>';
        $config['last_tag_close'] =     '</div>';
        $config['next_tag_open'] =      '<div>';
        $config['next_tag_close'] =     '</div>';
        $config['prev_tag_open'] =      '<div>';
        $config['prev_tag_close'] =     '</div>';
        $config['cur_tag_open'] =       '<div><a href="#"><strong>';
        $config['cur_tag_close'] =      '</strong></a></div>';
        $config['num_tag_open'] =       '<div>';
        $config['num_tag_close'] =      '</div>';
        //base url
        $config['base_url'] =           site_url() . '/customers/index/';
        //total rows
        $config['total_rows'] =         $this->customers_model->count_allcustomers();
        //per page
        $config['per_page'] =           20;
        //uri segment
        $config['uri_segment'] =        3;
        //number of links
        $config['num_links'] =          10;  
              
        // initialize the config made
        $this->pagination->initialize($config);
        
        // SET DATA
        $data['page_links'] = $this->pagination->create_links();
        
        //get all the data needed for the customers view
        $data['customers'] = $this->customers_model->get_allcustomers($config['per_page'],$this->uri->segment(3));

        //create the td link to the view
        $data['td_link'] = site_url() . '/customers/view/';

        //load the view
        $this->load->view('customers_view_all', $data);
    }

model:
Code:
#--------------------
    # get all the customers (only the field which are neccesary)
    #--------------------
    function get_allcustomers($per_page, $offset) {

        //select:
        $this->db->select('*');

        //from table:
        $this->db->from('customers');

        //join tables:
        $this->db->join('countries', 'countries.country_id = customers.country_id');
        $this->db->join('customertypes', 'customertypes.customertype_id = customers.customertype_id');
        $this->db->join('planttypes', 'planttypes.planttype_id = customers.planttype_id');
        
        //order
        $this->db->order_by("customer_name_1", "asc");
        
        //from table:
        $this->db->where('cluster_id', $this->session->userdata('cluster_id'));
              
        //limit for the pagination
        $this->db->limit($per_page, $offset);

        //get the results of the query:
        $query = $this->db->get();

        //if there is any result, return this:
        if ($query->num_rows() > 0) {
            
            //return all rows
            return $query->result_array();
        }
        else {

            //no records found
            return false;
        }
    }

    #--------------------
    # count all customers for the pagination
    #--------------------
    function count_allcustomers() {
        
        //from table:
        $this->db->where('cluster_id', $this->session->userdata('cluster_id'));
        
        //get the results of the query:
        $query = $this->db->get('customers');

        //if there is any result, return this:
        if ($query->num_rows() > 0) {
            
            //return all rows
            return $query->num_rows();
        }
        else {

            //no records found
            return false;
        }
    }
the view looks something like
Code:
<div id="search_div">
        &lt;form id="search_form" method="post" action="&lt;?php echo site_url() . '/customers/index/'; ?&gt;"&gt;
            Search: &lt;input type="text" name="search_query" value="&lt;?php $this-&gt;input->post('search_query'); ?&gt;" />
        &lt;/form&gt;
    </div>

off course the foreach with the data and the footer is following...




Theme © iAndrew 2016 - Forum software by © MyBB