php - Codeigniter search query, I want to add another condition to my search -


this table:

category:

{category_id , category } 

document:

{document_id, title, address, category} 

my controller:

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

my model:

class mymodel extends ci_model {     function __construct()     {         parent::__construct();     }      function search($keyword)     {         $this->db->like('name',$keyword);         $query  =   $this->db->get('document');         return $query->result();     } }  

and view:

<form action="<?php echo site_url('search/search_keyword');?>" method = "post"> <input type="text" name = "keyword" /> <input type="submit" value = "search" /> </form> <table> ?> foreach($results $row){ <?php     <tr>         <td><?php echo $row->title?></td>         <td><?php echo $row->category?></td>     </tr> <?php    } ?> </table> 

according controller , model shown above, can retrieve 1 keyword, title of document, want to:

add condition 1 if title = $keyword , category=$keyword2.

is possible in mvc or not?

try it.

  class mymodel extends ci_model  {   function __construct()   {     parent::__construct();     }    function search($keyword)   {     $this->db->where('name',$keyword);     $this->db->where('category',$keyword2);     $query  =   $this->db->get('document');     return $query->result();   } 

}

or can use condition.

 $this->db->like('name',$keyword);  $this->db->like('category',$keyword2); 

and define $keyword2 in controllers


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -