gpt4 book ai didi

php - 使用两个字段在 CodeIgniter 中进行表单搜索

转载 作者:行者123 更新时间:2023-11-30 00:08:22 27 4
gpt4 key购买 nike

嗨,我是新手,我想制作一个表单,使用两个字段在 CodeIgniter 中进行搜索,但我对 Controller 和模型感到困惑所以请帮助我..

    <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(); ?>

我对 Controller 和模型感到困惑..

提前致谢

最佳答案

在你的 Controller 中,你需要实现这样的东西:

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

希望对你有帮助。

关于php - 使用两个字段在 CodeIgniter 中进行表单搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24313184/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com