簡體   English   中英

如何設置LIKE子句CI

[英]How to set LIKE clause CI

控制器:

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;
    }

我想從數據庫中選擇標題包含$ match的所有行,但它將返回所有行。 我有一個輸入表格,在其中插入單詞。 在模型中,我想搜索每個標題中的單詞,並僅返回包含來自我的輸入表單的單詞的那些標題。 形成:

echo anchor('site/search','Search')."<br/><br/>";
    echo form_input('search','search');

我不太明白這個問題,但我認為這段代碼就是您所需要的

模型:

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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM