CodeIgniter Forums

Full Version: Search data in table using Codeigniter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
class Searchmodel extends CI_Model

   public function __construct() {

   function search($keyword)
       $query  =   $this->db->get('user');
       return $query->result_array();
Class Search extends CI_Controller

   public function __construct() {


   function search_keyword()

       $this->load->view('user/view', $data);


href='' rel='stylesheet' type='text/css'/>
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/bootstrap.min.css" >
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/bootstrap.css" >
<div class="container">

<h1 style="text-align: center">This is view of User</h1>
<!--site_url: Returns base_url + index_page + uri_string-->
   <form class="form-inline" role="form" action="<?php echo site_url().'/search/search_keyword';?>" method="post">
       <div class="form-group">
           <input type="text" class="form-control" name="search" placeholder="Search by firstname">
<button type="submit" class="btn btn-info" name="submit" >Search</button>
<table class="table-bordered">
       <th>User ID:</th>
       <th>First Name:</th>
       <th>Last Name:</th>
       <th>Created Date:</th>
       <th>Updated Date:</th>
       <th>Delete Flag:</th>
       <th>NEW DATA:</th>

   <?php foreach($users as $user){ ?>

           <tr style="text-align: center">
           <td><?=$user ['password']?></td>

               <td><a class="btn btn-primary" href="<?php echo site_url('cnt/add_cnt/'.$user['user_id']);?>">ADD</a></td>
               <td><a class="btn btn-success" href="<?php echo site_url('cnt/update_cnt/'.$user['user_id']);?>">EDIT</a></td>

               <td><a class="btn btn-danger" href="<?php echo site_url('cnt/delete_row/'.$user['user_id']); ?>">Delete</a></td>

   <?php } ?>

Please use code tags when placing code in the forums.

If you use the forums Reply to this topic button you will get a full editor
to place code into etc;
I want to display table and apply search at same page and display search result at same page, give me the suggestions.
@Sourabh Sen,

You could also use DataTables ( ) examples ( )
Use the form_open() function from the form helper.
Use the anchor() function from the url helper instead of <a href=

Use the alternative php style in views:
PHP Code:
<?php foreach($users as $user) : ?>
     //table rows here
<?php endforeach; ?>