Codeigniter Autocomplete Search From Database – jQuery UI
Codeigniter 16-Nov-2021

Codeigniter Autocomplete Search From Database – jQuery UI

How to implement jquery ui autocomplete search or textbox search with Database in codeigniter with example. In this Codeigniter tutorial, We will share with you how to implement an autocomplete search or textbox search with database using jquery ui example.

Today we will implement jquery ui autocomplete search simple and easy way. Just follow the few steps and implement autocomplete search in your codeigniter Application.

In this Codeigniter autocomplete search tutorial, we would love to share things step by step from scratch. We will use the jQuery ui for auto-complete search from datatabase, it is a library. Also we provide a live demo end of the tutorial.

Codeigniter jQuery ui Autocomplete Search with Ajax

  • Download Codeigniter Latest
  • Basic Configurations
  • Create Database With Table
  • Setup Database Credentials
  • Make New Controller
  • Create Views
  • Start Development server
  • Conclusion

Download Codeigniter Project

In this step we will download the latest version of Codeigniter, Go to this link Download Codeigniter. Download the fresh setup of codeigniter and unzip the setup in your local system xampp/htdocs/ and also rename your project folder name to demo.

Basic Configurations

Next we will set the some basic configuration on config.php file, so let’s go to application/config/config.php and open this file on text editor.

Set Base URL like this

$config['base_url'] = 'http://localhost/demo';

Create Database With Table

In this step, we need to create database name demo, so let’s open your phpmyadmin and create the database with the name demo . After successfully create a database, you can use the below sql query for creating a table in your database.

    id int(10) unsigned NOT NULL AUTO_INCREMENT,
     name varchar(255) COLLATE utf8_unicode_ci NOT NULL,
     email varchar(255) COLLATE utf8_unicode_ci NOT NULL, 
    PRIMARY KEY (id)

Setup Database Credentials

Nowwe need to connect this project to database, So go to application/config/ and open database.php file and set the datatabase credential.

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => '',
    'database' => 'demo',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE

Make Controller

Now we need to create a controller name Ajax.php. In this controller we will create some method/function name autocomplete() and search() for showing and searching a data from datatabse.

class Ajax extends CI_Controller {
    public function __construct()
    public function autocomplete(){
    public function search(){
        $term = $this->input->get('term');
        $this->db->like('name', $term);
        $data = $this->db->get("users")->result();
        echo json_encode( $data);

Create Views

Now we need to create view for showing autocomplete search bar, so go to application/views/ and here create one view name jquery-ui-autocomplete. After create this view put the below html in view.

<!DOCTYPE html>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Auto Complete Search Using Jquery UI -</title>
  <link rel="stylesheet" href="//">
  <link href="//" rel="stylesheet" id="bootstrap-css">
  <script src=""></script>
  <script src=""></script>
    padding: 10%;
    text-align: center;
<div class="container">
    <div class="row">
        <div class="col-12"><h2>Codeigniter 3 Auto Complete Search Using Jquery UI</h2></div>
        <div class="col-12">
            <div id="custom-search-input">
                <div class="input-group">
                    <input id="search" name="search" type="text" class="form-control" placeholder="Search" />
  var BASE_URL = "<?php echo base_url(); ?>";
 $(document).ready(function() {
    $( "#search" ).autocomplete({
        source: function(request, response) {
            url: BASE_URL + "ajax/search",
            data: {
                    term : request.term
            dataType: "json",
            success: function(data){
               var resp = $.map(data,function(obj){
    minLength: 1

Start Development server

For start development server, Go to the browser and hit below the url.



In this codeigniter autocomplete search tutorial – We have successfully create autocomplete search from datatabase using the jQuery ui library,

If you have any questions or thoughts to share, use the comment form below to reach us.