Live search with Datatable and mysql Codeigniter

Dear All I would like to share Live search using Datatable and codeigniter
you can download by Click here.

1. Create db
--
-- Database: `live_search`
--
CREATE DATABASE IF NOT EXISTS `live_search` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE `live_search`;

-- --------------------------------------------------------

--
-- Table structure for table `subscriber`
--

CREATE TABLE IF NOT EXISTS `subscriber` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `first` varchar(100) DEFAULT NULL,
  `last` varchar(100) DEFAULT NULL,
  `email` varchar(100) DEFAULT NULL,
  `date_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=35 ;

--
-- Dumping data for table `subscriber`
--

INSERT INTO `subscriber` (`id`, `first`, `last`, `email`, `date_created`) VALUES
(23, 'Web', 'sharing', 'webdevelopsharing@gmail.com', '2015-03-08 02:53:31'),
(24, 'html', 'css', 'webdevelopsharing@gmail.com', '2015-03-08 02:57:23'),
(25, 'php', 'mysql', 'webdevelopsharing@gmail.com', '2015-03-08 02:57:33'),
(26, 'sql', 'oracle', 'webdevelopsharing@gmail.com', '2015-03-08 02:57:42'),
(27, '.Net', 'test', 'webdevelopsharing@gmail.com', '2015-03-08 02:58:04'),
(28, 'NEiC', 'Kh', 'webdevelopsharing@gmail.com', '2015-03-08 02:58:49'),
(29, 'khmer', 'khmer', 'webdevelopsharing@gmail.com', '2015-03-08 02:58:57'),
(30, 'Youlay', 'hong', 'webdevelopsharing@gmail.com', '2015-03-08 02:59:12'),
(31, 'IT', 'web', 'webdevelopsharing@gmail.com', '2015-03-08 02:59:20'),
(32, 'designer', 'IT', 'webdevelopsharing@gmail.com', '2015-03-08 02:59:29'),
(33, 'Editor', 'web', 'webdevelopsharing@gmail.com', '2015-03-08 02:59:40'),
(34, 'Lina', 'Khaled', 'webdevelopsharing@gmail.com', '2015-03-08 02:57:16');

-- --------------------------------------------------------

--
-- Table structure for table `test`
--

CREATE TABLE IF NOT EXISTS `test` (
  `id_test` int(11) NOT NULL AUTO_INCREMENT,
  `id_subscriber` int(11) NOT NULL,
  `description` varchar(50) NOT NULL,
  PRIMARY KEY (`id_test`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=12 ;

--
-- Dumping data for table `test`
--

INSERT INTO `test` (`id_test`, `id_subscriber`, `description`) VALUES
(1, 23, 'test1'),
(2, 24, 'test2'),
(3, 25, 'test3'),
(4, 26, 'test4'),
(5, 27, 'test5'),
(6, 28, 'test6'),
(7, 29, 'test7'),
(8, 30, 'test8'),
(9, 31, 'test9'),
(10, 32, 'test10'),
(11, 33, 'test11');

2. Create veiw


    

 
Subscriber management



 



Subscriber management

table->generate(); ?>
3. Create controller
load->library('Datatables');
        $this->load->library('table');
        $this->load->database();
    }
    function index()
    {

        //set table id in table open tag
        $tmpl = array ( 'table_open'  => '' );
        $this->table->set_template($tmpl); 
        
        $this->table->set_heading('First Name','Last Name','Email','Description');

        $this->load->view('subscriber_view');
    }
    //function to handle callbacks
    function datatable()
    {
        $this->datatables->select('first,last,email,description')
        //->unset_column('id')
        ->from('subscriber')
        ->join('test', 'test.id_subscriber = subscriber.id');
        echo $this->datatables->generate();
    }
}
?>
4. load library
  download source above and pass library

Thanks! Any question?
Share on Google Plus

About Unknown

    Blogger Comment
    Facebook Comment

2 comments:

  1. Hello , Brother , we select limit data with datatable , I trying to select with limit , but still cannot . do we have the solution for this, because this datatable select all record from database , so make it slow,

    ReplyDelete