控制器:
function search()
{
$this->load->model('membership_model');
$query = $this->membership_model->search();
var_dump($query->result());}
型号:
function search()
{
$match = $this->input->post('Search');
$this->db->like('title',$match);
$q = $this->db->get('feeds');
return $q;
}
我想从我的数据库中选择title包含$ match的所有行,但它会返回所有行。我有一个输入表单,我插入单词。在模型中,我想在每个标题中搜索单词,并仅返回包含输入表单中单词的标题。 形式:
echo anchor('site/search','Search')."<br/><br/>";
echo form_input('search','search');
答案 0 :(得分:0)
我无法理解这个问题,但我认为这段代码就是你所需要的
型号:
function search($match){
$this->db->like('title',$match);
$q = $this->db->get('feeds');
return $q->result();
}
控制器:
function search_title()
{
$this->load->model('membership_model');
$search_value = $this->input->post('search');
$this->data['title'] = $this->membership_model->search($search_value );
}
查看:
<table>
<?php foreach($title as $value) : ?>
<tr>
<td> <?=$value->nameofcolumn; ?> </tr> //change the word nameofcolumn to the name of the column in your database what column you want to fetch
</tr>
<?php endforeach; ?>
</table>