[eluser]whiteae[/eluser]
I am having trouble with my pagination links due to multiple ways to look up items. I know I need the results in a session so that the links remain the same when clicked on. Here is my code.. It has 3 ways to display information. If no parameters, it displays all items, if parameters entered, then it displays items based on results, and lastly if the search input feature is used and the form is submitted, it displays the items based on that result. I'm new to this, so that might not be the best way to do things. I've had to change a lot without knowing exactly what to do at the beginning, so that's how I did it. Anyway I just need to know how I should go about this with saving the data according to how the user searched. Thanks in advance
Controller
Code:
function index ($brandAAIAID = '', $partNumQueryString = '')
{
//If parameters passed through URI
if($brandAAIAID != '')
{
//$session_data = array(
//'partNumLookup' => $partNumQueryString,
//'brandAAIAID' => $brandAAIAID
// );
//$this->session->set_userdata($session_data);
$data['columns'] = $this->item_list->column_names();
$data['brandName'] = $this->brand_label_model->getBrand();
$config['per_page'] = 30;
if($partNumQueryString == '')
{
$numRows =$this->search_model->getRowsBrandAAIAID($brandAAIAID);
$results = $this->search_model->searchBrandAAIAID($brandAAIAID, $config['per_page'],$this->uri->segment(3));
$data['items'] = $results;
}
else
{
$numRows =$this->search_model->getLookupRowsBoth($partNumQueryString, $brandAAIAID);
$results = $this->search_model->searchLookupBoth($partNumQueryString, $brandAAIAID, $config['per_page'],$this->uri->segment(3));
$data['items'] = $results;
}
// Load the model and perform the search
$config['base_url'] = base_url() . "index.php/items/index";
$config['total_rows'] = $numRows;
$config['num_links'] = 5;
$this->pagination->initialize($config);
$data['links'] = $this->pagination->create_links();
$data['brand']= urldecode($brandAAIAID);
$data['partNum'] = urldecode($partNumQueryString);
//load view
$this->load->view('itemHome', $data);
}//end if
//Else if search results submitted.
elseif($this->input->post('search'))
{
//Save data to a session
//$session_data = array(
// 'partNum' => $search_terms,
// 'brandLabel' => $brand_name,
// 'per_page' => 30
// );
// $this->session->set_userdata($session_data);
//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($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;
}
else
{
$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 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 if
//Else display all items on page.
else
{
$numRows =$this->item_list->get_rows();
$config['base_url'] = base_url() . "index.php/items/index";
$config['total_rows'] = $numRows;
$config['per_page'] = 30;
$config['num_links'] = 5;
$this->pagination->initialize($config);
$data['links'] = $this->pagination->create_links();
$data['columns'] = $this->item_list->column_names();
$data['brandName'] = $this->brand_label_model->getBrand();
//To paginate items
$data['items'] = $this->item_list->get_items($config['per_page'],$this->uri->segment(3));
//load view
$this->load->view('itemHome', $data);
}//end else
}//end function