Welcome Guest, Not a member yet? Register   Sign In
Search results saved to a session for pagination
#2

[eluser]whiteae[/eluser]
I need to figure this out today if anyone can help. Any feedback or insight would be great. Thanks.

I have updated my code so that it might be a little better to understand what I'm trying to do.

Code:
function index ($brandNameQueryString = '', $partNumQueryString = '')
   {    
       //Save parameters into session
           $session_data = array(
                'brandLabel' => urldecode($brandNameQueryString),
                'partNum' => $partNumQueryString
           );
           $this->session->set_userdata($session_data);

            //Save per page configuration for pagination.
            $config['per_page'] = 30;

            //if search results submitted.
           if($this->input->post('search'))
           {
               //Form validation
                $this->form_validation->set_rules('q', 'Search Criteria', 'trim|strip_tags');

                //Variables
                $search_terms = $this->input->get_post('q');
                $brand_name = $this->input->get_post('brandLabel');
                $config['per_page'] = 30;

                if(isset($brand_name) && $search_terms == '')
                {
                    $numRows =$this->search_model->getRowsBrand($brand_name);
                    $results = $this->search_model->searchByBrand($brand_name, $config['per_page'],$this->uri->segment(3));
                    $data['items'] = $results;
                }//end if
                elseif(isset($brand_name) && isset($search_terms))
                {
                    $numRows = $this->search_model->getRowsBoth($search_terms, $brand_name);
                    $results = $this->search_model->search($search_terms, $brand_name, $config['per_page'],$this->uri->segment(3));
                    $data['items'] = $results;
                }//end elseif
           }//end if
            elseif($this->session->userdata('brandLabel') != '')
            {
                //If only brand name supplied, search by brand, else search by both brand name and part number.
                if($this->session->userdata('partNum') == '')
                {
                    $numRows =$this->search_model->getRowsBrand($this->session->userdata('brandLabel'));
                    $results = $this->search_model->searchByBrand($this->session->userdata('brandLabel'), $config['per_page'],$this->uri->segment(3));
                    $data['items'] = $results;
                }
                else
                {
                   $numRows =$this->search_model->getRowsBoth($this->session->userdata('partNum'), $this->session->userdata('brandLabel'));
                   $results = $this->search_model->search($this->session->userdata('partNum'), $this->session->userdata('brandLabel'), $config['per_page'],$this->uri->segment(3));
                   $data['items'] = $results;
                }
            }//end elseif
            else
            {
                $numRows =$this->item_list->get_rows();
                $data['items'] = $this->item_list->get_items($config['per_page'],$this->uri->segment(3));
            }//end else
          
             //Pagination
            $config['base_url'] = base_url() . "index.php/items/index";
            $config['total_rows'] = $numRows;
            $data['columns'] = $this->item_list->column_names();
            $data['brandName'] = $this->brand_label_model->getBrand();
            $config['num_links'] = 5;
            $this->pagination->initialize($config);
            $data['links'] = $this->pagination->create_links();
            //load view
            $this->load->view('itemHome', $data);
              
   }//end function


Messages In This Thread
Search results saved to a session for pagination - by El Forum - 07-25-2012, 11:16 AM
Search results saved to a session for pagination - by El Forum - 07-26-2012, 05:05 AM
Search results saved to a session for pagination - by El Forum - 07-26-2012, 10:01 AM
Search results saved to a session for pagination - by El Forum - 08-29-2012, 11:17 PM
Search results saved to a session for pagination - by El Forum - 08-30-2012, 06:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB