DEV Community

Robert Look
Robert Look

Posted on

Search Data From Database In Codeigniter With Example

This tutorial is search data from database in Codeigniter based on CodeIgniter and Bootstrap design and other designs I share with you how to display data from database in PHP using Codeigniter. When we want to retrieve a record filtered by a keyword, we have to use the search function. we have to search for all records to get the needed one record. So, here I will explain to you how to display data from database in Codeigniter simple search button.

Search Data From Database In Codeigniter With Example

Controller

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

class Searchcontroller extends CI_Controller {

  public function searchfunction()
        {
            $data['searchdata']=$this->Search_Model->GetSearchdata();
            $this->load->view('search',$data);
        }
}
Enter fullscreen mode Exit fullscreen mode

Model

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

class Search_Model extends CI_Model {

public function GetSearchdata()
    {
        $this->db->select("*"); 
        $this->db->like('tutorial_name',$this->input->get('search'));
        $query = $this->db->get("tutorial_name"); 
        return $query->result();
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)