gpt4 book ai didi

php - 使用组合框 codeigniter 搜索数据

转载 作者:行者123 更新时间:2023-11-29 08:08:12 26 4
gpt4 key购买 nike

我是乔瓦尼,我的代码出现问题,似乎我的代码可以工作,但为什么结果与我的组合框中的值不匹配..

你能告诉我出了什么问题吗?

这是我的代码(在 Controller 上。函数 pencarian_indeks)

function pencarian_indeks() {

//muat library form validation
$this->load->library('form_validation');

if(isset($_POST['submit']))
{
//set aturan validasi untuk setiap field isian
$this->form_validation->set_rules('tanggal', 'Tanggal', 'required');
$this->form_validation->set_rules('kategori', 'Kategori', 'required');
$this->form_validation->set_rules('tahun', 'Tahun', 'required');
$this->form_validation->set_rules('bulan', 'Bulan', 'required');


//cek apakah form validasi berhasil
if ($this->form_validation->run() == FALSE)//jika validasi gagal
{

$this->session->set_flashdata('pesan', validation_errors());
redirect(base_url() . 'indeks');
}
else //jika validasi berhasil
{
$data['kategori'] = $this->input->post('kategori');
$data['tanggal'] = $this->input->post('tanggal');
$data['bulan'] = $this->input->post('bulan');
$data['tahun'] = $this->input->post('tahun');

$this->db->where('DAY(created_at)',$data['tanggal']);
$this->db->where('MONTH(created_at)',$data['bulan']);
$this->db->where('YEAR(created_at)',$data['tahun']);

$this->db->where('kategori', $data['kategori']);
$this->db->from('news');

//Pagination init
$pagination['base_url'] = base_url().'/pencarian/index/page/';
$pagination['total_rows'] = $this->db->count_all_results();
$pagination['full_tag_open'] = "<p><div class=\"pagination\">";
$pagination['full_tag_close'] = "</div></p>";
$pagination['cur_tag_open'] = "<span class=\"current\">";
$pagination['cur_tag_close'] = "</span>";
$pagination['num_tag_open'] = "<span class=\"disabled\">";
$pagination['num_tag_close'] = "</span>";
$pagination['per_page'] = "3";
$pagination['uri_segment'] = 4;
$pagination['num_links'] = 4;

$this->pagination->initialize($pagination);

$data['query'] = $this->news_model->indeks_berita($pagination['per_page'],$this->uri->segment(4,0),$data['tahun'],$data['bulan'],$data['tanggal'],$data['kategori']);

print_r($data['query']);//coba dicek dlu datanya..
exit;

$this->load->vars($data);
$data['hasil5'] = $this->news_model->tampil_populer(2);
$data = array_merge($data,admin_info());
$this->parser->parse('frontend/indeks/indeks',$data);

}
} else {
echo "Hasil Pencarian Tidak Ditemukan!!";
}



}

在我的模型上(函数 indeks_berita)

    function indeks_berita($perPage, $uri,$tanggal,$bulan,$tahun,$kategori) {
$this->db->select('*');

if($tahun)
$this->db->where('YEAR(created_at)',$tahun);
if($bulan)
$this->db->where('MONTH(created_at)',$bulan);
if($tanggal)
$this->db->where('DAY(created_at)',$tanggal);
if($kategori)
$this->db->where('kategori', $kategori);
$this->db->order_by('id', 'asc');

$getData = $this->db->get('news', $perPage, $uri);

print_r ($this->db->last_query());
//print_r ($getData->result_array());
exit();

if ($getData->num_rows() > 0){
return $getData->result_array();
}else{
return null;
}
}

在我看来(组合框)

<p>Lihat Arsip Tanggal :
<select name="kategori">
<option value="" selected>Pilih kategori</option>
<option value="news">News</option>
<option value="bandung_city">Bandung City</option>
<option value="hot_gossip">Hot Gossip</option>
<option value="sainstek">Sains & Tek</option>
<option value="kriminal">Kriminalitas</option>
<option value="persibnews">#PERSIBONTHENEWS</option>
</select>
<select name="tahun">
<option value="" selected>Pilih Tahun</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
</select>
<select name="bulan">
<option value="" selected>Pilih Bulan</option>
<option value="1">Januari</option>
<option value="2">Februari</option>
<option value="3">Maret</option>
<option value="4">April</option>
<option value="5">Mei</option>
<option value="6">Juni</option>
<option value="7">Juli</option>
<option value="8">Agustus</option>
<option value="9">September</option>
<option value="10">Oktober</option>
<option value="11">November</option>
<option value="12">Desember</option>
</select>

<select name="tanggal">
<option value="" selected>Pilih</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>

<input type="submit" value="Cari!" name="cari" id="cari"/>

这是我提交该代码时的输出查询:

SELECT * FROM (`news`) WHERE YEAR(created_at) = '2' AND MONTH(created_at) = '17' AND DAY(created_at) = 'bandung_city' AND `kategori` = '2014' ORDER BY `id` asc LIMIT 3

(好像不对)

谢谢你,如果你能帮我找出问题所在,我很高兴

最佳答案

您的表格action似乎不正确,您没有 indeks里面的方法indeks Controller 。

更改如下

<form action="<?php echo base_url(); ?>indeks/pencarian_indeks" method="post">

关于php - 使用组合框 codeigniter 搜索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22291866/

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