Creating live search with AJAX and CodeIgniter



PHP Snippet 1:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Search_model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
    }

    public function get_autocomplete($search_data)
    {
        $this->db->select('slug, name');
        $this->db->like('slug', $search_data);
        $this->db->like('name', $search_data);
        $query = $this->db->get('properties', 10);
        return $query->result();
    }
}

?>

PHP Snippet 2:

<input name="search_data" id="search_data" class="" value="" 
    data-label="Search for a property, a unit, or an resident..." 
    type="text" onkeyup="ajaxSearch();" />