我是新的Codeigniter。我试图搜索数据库中的记录与类似的查询。我想所有的结果与日期02-2023,但它也显示结果与03-2023任何帮助
这是我的模特课。
public function get_filter($limit, $start, $newvar) {
$this->db->limit($limit, $start);
$this->db->like('date', $newvar);
$query = $this->db->get('mytable');
return $query->result_array();
}
public function filter_count($newvar) {
$this->db->like('date', $newvar);
$this->db->from("mytable");
$count = $this->db->count_all_results();
return $count;
}
我已经尝试了上面部分给出的代码。如果需要更多的细节,请告诉我。我希望得到所有日期为02-2023的记录,但“喜欢”短语也包括03-2023的记录。我总是尝试在发布到论坛之前搜索答案。但不幸的是,我在以前的帖子中找不到它的解决方案。
我还注意到,如果我手动传递“02-2023”,那么它工作得相当好,但不能与$newvar一起工作,而$newvar的值是02-2023(已确认)。
1条答案
按热度按时间tkqqtvp11#
案例:1尝试这个$newvar日期值类似于“2023-03-03”。
案例:2我假设您在数据库中存储的日期类似于'Y-m-d H:i:s'。