嗨,我是新手,我想用一个表格在CodeIgniter中使用两个字段进行搜索,但我对控制器&楷模 所以请帮帮我..
<input id="srchFld" class="srchTxt" name="keyword" type="text" value="<?php echo $this->session->userdata("keyword"); ?>" />
<select class="srchTxt" name="kategori">
<option>All</option>
<?php
foreach ($kat as $kategori){
$id = $kategori['id'];
$nama_kategori = $kategori['nama_kategori'];
$created_at = $kategori['created_at'];
?>
<option value="<?php echo $id; ?>"><?php echo $nama_kategori; ?></option>
<?php } ?>
</select>
<?php echo form_close(); ?>
我对控制器&amp;模型..
先谢谢
答案 0 :(得分:0)
在您的控制器中,您需要实现以下内容:
function search(){
$filters['keyword'] = $this->input->post('keyword', TRUE);
$filters['kategori'] = $this->input->post('kategori', TRUE);
// pass this params to the model
$data = $this->yourmodel->search($filters);
// pass search results to the view
$this->load->view('view_file', $data);
}
在您的模型中
function search($filters){
$sql = "SELECT * FROM some_table WHERE some_field LIKE ? AND other_field = ?";
return $this->db->query($sql, array($filters['keyword'], $filters['kategori']))->result_array();
}
我希望我帮助过你。