jqueryajaxcodeigniterjquery-ui-autocomplete

Auto Compleate codeigniter Not Working On Server


This is My code Actually Working IN my Local Server But When i Upload Online Its Not Working

My View Page

<input type="text" class="typeahead form-control" onkeypress="getmedicien(0)"  id="medicine_name0"  name="medicine_name0">

function getmedicien(n){   
          $("#medicine_name"+n).autocomplete({
               source: "<?php echo site_url('doctor_prescription/get_mediciens'); ?>",
               select: function(event,ui){
                event.preventDefault(); 
                 $("#medicine_name"+n).val(ui.item.value);
                 $("#medicine_id"+n).val(ui.item.id); 
                }
          }); 
    }

This My Controller code

public function get_mediciens(){
          $term = $this->input->post('term'); 
            $this->db->distinct();
            $this->db->select("id,name");
            $this->db->from('medicine');
            $this->db->like('name', $term);
            $this->db->group_by('medicine.name');
            $this->db->limit(10);
            $query = $this->db->get();
            $mediData = array();
            foreach ($query->result_array() as $row)
            {
                 $data['id']    = $row['id'];
                $data['value']  = $row['name']; 
               array_push($mediData, $data);
            }
            echo json_encode($mediData);  
    }

Solution

  • If you're getting Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column(...) it means your production database is in strict mode (which is a good thing), making it a little bit less flexible in terms of what it considers valid.

    One of many rules being enforced is that when using group by, the first element in your select statement must be one of the elements you are grouping by.

    try changing $this->db->group_by('medicine.name'); for $this->db->group_by('id'); and you should be OK