Model
[b]<?php
class Searchmodel extends CI_Model
{
public function __construct() {
parent::__construct();
}
function search($keyword)
{
$this->db->like('first_name',$keyword);
$query = $this->db->get('user');
return $query->result_array();
}
}
?>[/b]
Controller
[b][b]<?php
Class Search extends CI_Controller
{
public function __construct() {
parent::__construct();
$this->load->model('searchmodel');
}
function search_keyword()
{
$keyword=$this->input->post('submit');
$data['users']=$this->searchmodel->search($keyword);
$this->load->view('user/view', $data);
}
}
?>[/b][/b]
View
<[b]link href='http://fonts.googleapis.com/css?family=Marcellus' 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">
</div>
<button type="submit" class="btn btn-info" name="submit" >Search</button>
</form>
<table class="table-bordered">
<tr>
<th>User ID:</th>
<th>First Name:</th>
<th>Last Name:</th>
<th>Email:</th>
<th>Password:</th>
<th>Created Date:</th>
<th>Updated Date:</th>
<th>Delete Flag:</th>
<th>NEW DATA:</th>
<th>EDIT:</th>
<th>DELETE:</th>
</tr>
<?php foreach($users as $user){ ?>
<tr style="text-align: center">
<td><?=$user['user_id']?></td>
<td><?=$user['first_name']?></td>
<td><?=$user['last_name']?></td>
<td><?=$user['email']?></td>
<td><?=$user ['password']?></td>
<td><?=$user['created_at']?></td>
<td><?=$user['updated_at']?></td>
<td><?=$user['is_deleted']?></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>
</tr>
<?php } ?>
</table>
</div>[/b]