搜索功能在codeigniter中不能按我需要的方式工作

时间:2017-02-06 17:38:10

标签: php codeigniter codeigniter-3

我有一个搜索功能,它会一直显示我想要的所有记录,以便隐藏所有记录,只显示我正在搜索的记录。

控制器只是功能

   function search_keyword()
    {
        $keyword    =   $this->input->post('keyword');
        $data['row']    =   $this->inbound_model->search($keyword);
        $this->load->view('pages/test',$data);
    }

只模拟函数

function search($keyword)
    {
        $this->db->like('RequestNumber',$keyword);

        $query  =   $this->db->get('requestsnew');
        return $query->result();
    }

查看

<form action="<?php echo site_url('inbound/search_keyword');?>" method = "post">
<input type="text" name = "keyword" />
<input type="submit" value = "Search" />
</form>

<?php foreach($row as $r){ ?>
    <tr>
        <td><?php echo $r->RequestNumber?></td>
           <td><?php echo $r->EmpName?></td>

    </tr>
<?php } ?>
</table>

1 个答案:

答案 0 :(得分:0)

我认为只需将like更改为模型中的where子句。

function search($keyword)
{
    $this->db->where('RequestNumber',$keyword);

    $query  =   $this->db->get('requestsnew');
    return $query->result();
}