• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Filtering Database Results

#1
[eluser]mikeshima[/eluser]
Hi guys,

I'm trying to create a filter screen to include a where statement depending on the users form input but I'm struggling to set an arrays value within the model - it sounds very trivial I feel stupid asking.

Controller Code
Code:
public function filterLinks($param = 'form')
    {    
        if ($param == 'form') {
            $this->load->helper('form');
            $this->load->model('paypal_model');
            
            $data = array('paypallinks' => $this->paypal_model->filterResults());
            $template = array(
                'title' => 'Filter Paypal Links',
                'content' => $this->load->view('paypal', $data, TRUE)
            );
            
            $this->load->view('template', $template);
        }

        elseif ($param == 'submit') {
            $this->load->model('paypal_model');
                    
            if ($this->paypal_model->filterPref()) {
                redirect('paypal/filterLinks/form');
            } else {
                redirect('paypal');
            }
        }
    }

Model Code


Note: the value $filterArray is created in the class outwith the constructor
Code:
class Paypal_Model extends Model
{                        
    public $filterArray;
Code:
public function filterPref(){    
        $this->filterArray = array(
            'sortStatuses' => trim($this->input->post('sortStatuses')),
            'sortStaff' => trim($this->input->post('sortStaff')),
            'sortClient' => trim($this->input->post('sortClient')),
            'sortDisplay' => trim($this->input->post('sortDisplay'))
        );
        
        if ($this->filterArray['sortDisplay'] < 1){
            $this->session->set_flashdata('message',
            '<p class="error">You must display more than one result.</p>');
            
        }else{        
            $this->session->set_flashdata('message',
             '<p class="success">Links have been sorted.</p>');                    
            return true;
        }
        return false;
    }
    
    public function filterResults(){
        if($this->filterArray['sortDisplay'] > 1)
        {
            $this->db->select('linkmanager.*, users.name as staffname');
            $this->db->join('users', 'users.id = linkmanager.linkby', 'left');
            $paypallinks = $this->db->get('linkmanager');
            return $paypallinks->result();        
        }
    }

The problem I'm having is that once the user hits submit on the form it doesn't store the variable of that has been passed in, in the array filterArray. Yet strangely, the error messaging for when there is less than one result being displayed works fine. I'm having a very sore head from this code - any help would be appreciated.

Thanks


Messages In This Thread
Filtering Database Results - by El Forum - 08-02-2010, 05:45 AM
Filtering Database Results - by El Forum - 08-02-2010, 09:13 AM
Filtering Database Results - by El Forum - 08-02-2010, 09:16 AM
Filtering Database Results - by El Forum - 08-02-2010, 09:27 AM
Filtering Database Results - by El Forum - 08-02-2010, 10:09 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.