在Codeigniter中搜索数据 [英] Search Data in Codeigniter
本文介绍了在Codeigniter中搜索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您可以帮助在Codeigniter中创建一个简单的搜索。我不知道如何。请
Can you help to create a simple search in Codeigniter. i don`t know how. please.
这是我的数据库名称tbl_dash
this is my database name tbl_dash
tbl_dash
id | name | Note
_________________________
1 | erwin | Baker
2 | flores | Coke
请帮助我!:(
推荐答案
以下是您可以如何做。
查看
Here is how you can do it.
View
<form action="<?php echo site_url('search/search_keyword');?>" method = "post">
<input type="text" name = "keyword" />
<input type="submit" value = "Search" />
</form>
控制器
Class Search Extends CI_Contrller
{
function __construct()
{
parent::__construct();
$this->load->model('mymodel');
}
function search_keyword()
{
$keyword = $this->input->post('keyword');
$data['results'] = $this->mymodel->search($keyword);
$this->load->view('result_view',$data);
}
}
模型
Class Mymodel Extends CI_Model
{
function __construct()
{
parent::__construct();
}
function search($keyword)
{
$this->db->like('name',$keyword);
$query = $this->db->get('tablename');
return $query->result();
}
}
EDITS:
视图显示数据。 result_view.php
EDITS :
Here is the view to display data. result_view.php
<table>
?>
foreach($results as $row){
<?php
<tr>
<td><?php echo $row->Company?></td>
<td><?php echo $row->Source?></td>
<td><?php echo $row->SavePitch?></td>
<td><?php echo $row->Results?></td>
<td><?php echo $row->Status?></td>
<td><?php echo $row->user_id?></td>
</tr>
<?php
}
?>
</table>
这篇关于在Codeigniter中搜索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文