Welcome Guest, Not a member yet? Register   Sign In
GET function does not work.
#3

(This post was last modified: 08-14-2018, 05:47 PM by HarrysR.)

(08-14-2018, 04:14 PM)@php_rocs Wrote: Your 1st condition could return null and still execute. Maybe what you want is...
 if( !is_null($this->input->get('petStatus')) || !is_null($this->input->get('petType')) )
or you can check to see if it is set...
 if(isset($this->input->get('petStatus')) || isset($this->input->get('petType')) )


Also, you could just output the input object and view it's contents.

As for your second question it doesn't matter what order the variables are in as long as you refer to them by their get id it will always be correct.

Well.. still nothing.. the problem persists.. 

I tried the "isset" way i get an error that i can't use "isset"..
I tried the !is_null as you can see below and the results are still the same. if i have ?petType=1&petStatus=2 in url, the data do not get filtered.

Pet_model.php
Code:
public function filter_pets($pet_entry_id = 0, $pet_entry_slug = FALSE){

     $this->db->join('pet_categories', 'pet_categories.pet_category_id = pets.category_id');
     $this->db->join('ws_zone', 'ws_zone.zone_id = pets.pet_city');
     $this->db->join('users', 'users.user_id = pets.user_id');
     $this->db->join('contact_info', 'contact_info.contact_info_id = pets.contact_info_id');

     if(!is_null($this->input->get('petStatus')) || !is_null($this->input->get('petType')) ){

       if ( $this->input->get('petStatus') ){
         $pet_data = array(
           'pet_status' => $this->input->get('petStatus')
         );
       } elseif ( $this->input->get('petType') ){
         $pet_data = array(
           'category_id' => $this->input->get('petType')
         );
       } elseif ( !is_null($this->input->get('petStatus')) && !is_null($this->input->get('petType')) ){
         $pet_data = array(
           'pet_status' => $this->input->get('petStatus'),
           'category_id' => $this->input->get('petType')
         );
       }

       $query = $this->db->get_where('pets', $pet_data);
       return $query->result_array();
     } else {

     $query = $this->db->get('pets');
     return $query->result_array();
   }

 }



Pets.php (controller)
Code:
public function index(){

   $data['pets'] = $this->pet_model->filter_pets();

   $this->load->view('templates/header', $data);
   $this->load->view('pets/index', $data);
   $this->load->view('templates/footer', $data);
 }

JQuery
Code:
 $('#filters select').change(function(){
     let filters = [];
     $('#filters select').each(function(){
         const string = $(this).attr('id');
         const value = $(this).val();
         if(value != '') {
           filters.push(string + '=' + value);
         }
     });
     window.location.search = filters.join('&');
 });


HTML file
Code:
  <div class="col-lg-2" id="filters">    
       <div class="form-group mt-3">
         <select class="form-control filter-selection" id="petStatus">
           <option value="">-- Status --</option>
           <option value="1">Lost</option>
           <option value="2">Found</option>
         </select>
       </div>

       <div class="form-group input-group">
         <div class="input-group-prepend">
           <span class="input-group-text"><i class="fas fa-paw"></i></span>
         </div>
         <select class="form-control filter-selection" id="petType">
           <option value="">-- Type --</option>
           <option value="1">Cat</option>
           <option value="2">Dog</option>
           <option value="3">Other</option>
         </select>
       </div>
</div>

//Life motto
if (sad() == true) {
     sad().stop();
     develop();
}
Reply


Messages In This Thread
GET function does not work. - by HarrysR - 08-14-2018, 02:21 PM
RE: GET function does not work. - by php_rocs - 08-14-2018, 04:14 PM
RE: GET function does not work. - by HarrysR - 08-14-2018, 05:40 PM
RE: GET function does not work. - by php_rocs - 08-15-2018, 04:47 AM
RE: GET function does not work. - by HarrysR - 08-15-2018, 08:58 AM
RE: GET function does not work. - by php_rocs - 08-15-2018, 09:10 AM
RE: GET function does not work. - by HarrysR - 08-15-2018, 09:43 AM
RE: GET function does not work. - by php_rocs - 08-15-2018, 10:25 AM
RE: GET function does not work. - by HarrysR - 08-15-2018, 11:28 AM
RE: GET function does not work. - by HarrysR - 08-15-2018, 12:35 PM



Theme © iAndrew 2016 - Forum software by © MyBB