• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GET function does not work.

#10
@php_rocs,

FINALLY MADE IT!!!
It was simpler than i thought and it works like a charm!!

Pet_model
Code:
   public function get_filtered_pets($pet_status, $pet_type){

     $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( !empty($pet_status) || !empty($pet_type) ) {
       if( isset($pet_status) ){
         $pet_data['pet_status'] = $pet_status;
       }

       if( isset($pet_type) ){
         $pet_data['category_id'] = $pet_type;
       }

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

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

 }

Pets controller
Code:
 public function index(){

   $pet_status = $this->input->get('petStatus');
   $pet_type = $this->input->get('petType');

   $data['pets'] = $this->pet_model->get_filtered_pets($pet_status, $pet_type);

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

The only problem now is Jquery beacause i can't pass multiple values in url string but it replaces the old ones. If you have any solutions on that please feel free to tell me.
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('&')
 });

Any suggestions on this particular filtering function are welcomed!

//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

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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