Welcome Guest, Not a member yet? Register   Sign In
Having A Hard Time With Autosuggest in CI
#1

Hi can somebody help me debug my autosuggest code? Please.

View (jquery is included)
Code:
<script>
  function lookup(inputString) {
     if(inputString.length == 0) {
        $('#suggestions').hide();
     } else {
        $.post("http://site/loan_percentage/autocomplete/", {queryString: ""+inputString+""}, function(data){
           if(data.length > 0) {
              $('#suggestions').show();
              $('#autoSuggestionsList').html(data);
           }
        });
     }
  }

  function fill(thisValue) {
     $('#id_input').val(thisValue);
     setTimeout("$('#suggestions').hide();", 200);
  }  
</script>

<input name="name" id="id_input" type="text" onkeyup="lookup();">

<div id="suggestions">
  <div class="autoSuggestionsList_l" id="autoSuggestionsList"></div>
</div>

Controller
Code:
class Loan_percentage extends MY_Controller {

   public function __construct (){
       parent::__construct();
   }

   public function index (){
       $this->data['page_title'] = 'Loan Percentage';
       $this->load_view('site/loan_percentage');
   }
   
   public function autocomplete(){
    $this->load->model('loan_percentage_model','get_data');
       $query = $this->get_data->get_autocomplete();

    foreach($query->result() as $row):
        echo "<li id=''>".$row->username."</li>";
    endforeach;    
   }
}

Model
Code:
class Loan_percentage_model extends MY_Model{

   public function __construct (){
       parent::__construct();
   }

   public function get_autocomplete(){
       $this->db->select('username');
        $this->db->like('username',$this->input->post('queryString'));
        return $this->db->get('tbl_user_accounts', 10);     
   }

}

Thanks.
Reply
#2

It's okay to say it's giving you a hard time but to understand your request better, what is it doing or not doing?
Jamie Bond
Full time International Development undergraduate.
Part time website developer.
Reply
#3

For one your missing the 3rd parameter in your get

$this->db->get('mytable', 10, 20);
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

In your controller you have to route the post var to your model method like

PHP Code:
$this->get_data->get_autocomplete($this->input->post('queryString'));

and 
in your model

   
public function get_autocomplete($post){
       
$this->db->select('username');
        
$this->db->like('username',$post);
        return 
$this->db->get('tbl_user_accounts'10);     
   } 

Maybe this gives you the result you're looing for.

Reply




Theme © iAndrew 2016 - Forum software by © MyBB