2017-02-21 3 views
1

ich Problem mit der automatischen Vervollständigung haben in Codeigninter und JQuery Ich habe einen Controllerautomatische Vervollständigung Mehrere Werte in Codeigniter

<?php 
public function search() { 
    $user = $_GET['term']; 
    $query = $this 
      ->db 
      ->select('nama_kota') 
      ->like('nama_kota', $user) 
      ->get('kota'); 
    if ($query->num_rows() > 0) { 
     foreach ($query->result_array() as $row) { 
      $row_set[] = htmlentities(stripslashes($row['nama_kota'])); 
     } 
     echo json_encode($row_set); 
    } 
} 
?> 

I

<script> 
    $(function() { 
     var availableTags = "<?php echo base_url('admin/kota/search'); ?>"; 
     $("#user-input").autocomplete({ 
      source: availableTags 
     }); 
    }); 
</script> 
<input id="user-input" type="text" name="nama_kota" placeholder="Search User" autocomplete="on"> 

alles seine Ordnung eine Aussicht, aber ich versuche, mehrere Werte

<script> 
    $(function() { 
     var availableTags = "<?php echo base_url('admin/kota/search'); ?>"; 
     function split(val) { 
      return val.split(/,\s*/); 
     } 
     function extractLast(term) { 
      return split(term).pop(); 
     } 
     $("#user-input").autocomplete({ 
      minLength: 0, 
      source: function (request, response) { 
       // delegate back to autocomplete, but extract the last term 
       response($.ui.autocomplete.filter(
         availableTags, extractLast(request.term))); 
      }, 
      focus: function() { 
       // prevent value inserted on focus 
       return false; 
      }, 
      select: function (event, ui) { 
       var terms = split(this.value); 
       // remove the current input 
       terms.pop(); 
       // add the selected item 
       terms.push(ui.item.value); 
       // add placeholder to get the comma-and-space at the end 
       terms.push(""); 
       this.value = terms.join(", "); 
       return false; 
      } 
     }); 
    }); 
</script> 
<input id="user-input" type="text" name="nama_kota" placeholder="Search User" autocomplete="on"> 

keine Arbeit und nutzen ableTags nur addres lesen keine Funktion in der Steuerung url was falsch Jungs mir bitte helfen, Dank

+0

Add code not image !! –

+0

Welche Beispielausgabe möchten Sie? –

+0

versuchen, echo $ user = $ _GET ['term']; in Controller – Shibon

Antwort

0

die Ausgabe geben off Sie benötigen Wenn Sie dieses

zB benötigen. Name, Adresse, Blutgruppe.

mit einer Leistung von automatischen Vervollständigung Anruf

+0

i Anzeige nama_kota von kota Tabelle wollen –

+0

nur Namen oder andere Felder –

+0

i Datensatz anzuzeigen aus Tabelle kota im Feld nama_kota wollen –

0

Sorry For späte Antwort bin ich sehr, sehr beschäftigt in meiner Arbeit dies Aufruf JS

<script> 

    jQuery("#h_student_name").autocomplete({ 
     minLength: 0, 
     source: "DropdownController/hostel_students/" + $("#h_student_name").val(), 
     autoFocus: true, 
     scroll: true, 
     dataType: 'jsonp', 
     select: function (event, ui) { 
      jQuery("#h_student_name").val(ui.item.contactPerson); 
      jQuery("#h_student_id").val(ui.item.code); 
     } 
    }).focus(function() { 
     jQuery(this).autocomplete("search", ""); 
    }); 
</script> 

und dies ist Controller für Anruf-Controller

<?php 
//Hostel Student Auto compelete 
public function hostel_students(){ 


    $term = trim(strip_tags($this->input->get('term'))); 
    if($term == ''){ 
     $like = $term; 
     $result_set = $this->DropdownModel->hostel_students(array('hostel_status_id' => 1)); 
     $labels = array(); 
     foreach ($result_set as $row_set) { 
      $labels[] = array(
       'label' => $row_set->student_name.' S/D '.$row_set->father_name.' ,Form# '.$row_set->form_no.' ', 
       'code' => $row_set->hostel_id, 
       'value' => $row_set->student_name, 
      ); 
     } 
     $matches = array(); 
     foreach($labels as $label){ 
      $label['value'] = $label['value']; 
      $label['code'] = $label['code']; 
      $label['label'] = $label['label']; 

      $matches[] = $label; 
     } 
     $matches = array_slice($matches, 0, 10); 
     echo json_encode($matches); 
    } else if($term != ''){ 
     $like = $term; 
     $result_set = $this->DropdownModel->hostel_students(array('hostel_status_id' => 1), $like); 
     $labels = array(); 
     foreach ($result_set as $row_set) { 
      $labels[] = array(
       'label' => $row_set->student_name.' S/D '.$row_set->father_name.' ,Form# '.$row_set->form_no.' ', 
       'code' => $row_set->hostel_id, 
       'value' => $row_set->student_name, 
      ); 
     } 
     $matches = array(); 
     foreach($labels as $label){ 
      $label['value'] = $label['value']; 
      $label['code'] = $label['code']; 
      $label['label'] = $label['label']; 

      $matches[] = $label; 
     } 
     $matches = array_slice($matches, 0, 10); 
     echo json_encode($matches); 
    } 
} 
?> 

und dies ist ein Modell für Anruf

<?php 
// Hostel student autocomplete  
public function hostel_students($where, $like = NULL){ 
    if($like): 
     $this->db->like('student_name', $like); 
     $this->db->or_like('form_no', $like); 
     $this->db->or_like('college_no', $like); 
    endif; 
     $this->db->join('student_record', 'student_record.student_id=hostel_student_record.student_id'); 
     return $this->db->where($where)->get('hostel_student_record')->result(); 
    } 
} 
?> 

Haben Sie ein Problem Kommentar Ich werde heute online

Verwandte Themen