gpt4 book ai didi

php - 使用Codeigniter计算所有结果方法时出现数据库错误

转载 作者:行者123 更新时间:2023-11-29 19:18:32 25 4
gpt4 key购买 nike

我目前正在为我的系统做一个事件调度模块。我想计算所有月份的所有计划事件。例如,今年 3 月我有 10 个事件,然后 4 月份有 5 个传入事件,但我遇到错误“发生数据库错误” Error message Controller

$data['getAll'] = $this->CrudModel->count_all('events');

型号

public function count_all($table)

{
// $this->db->select('service');
// $this->db->from($table);
// $this->db->where('date LIKE','%'.$month.'%'); // 2017-03-04
// $num_results = $this->db->count_all_results();
// return $num_results->result();
$query = $this->db->query("SELECT date, service from $table");
foreach ($query->result() as $row)
{
# code...
$date = $row->date;
$service = $row->service;
$date_explode = explode('-', $date);
$year = $date_explode[0];
$month = $date_explode[1];
$day = $date_explode[2];
$service_explode = explode(',', $service);
echo "<pre>";
print_r($date_explode);
print_r($service_explode);
echo "</pre>";
$this->db->like('date',$month); // 2017-03-04
$num_results = $this->db->count_all_results();
}
// return $query->result();
}

问题:我的查询有误吗?如果是,那是什么?或者有任何其他建议如何计算所有预定的事件?

注意:我只使用了一个日期..预定日期(例如,我在2017年3月4日安排了事件),我没有结束日期(因为我在html中使用了日期输入类型)

最佳答案

您必须指定表名称

$this->db->count_all_results("table");

Active Record Documentation for count_all_results();

关于php - 使用Codeigniter计算所有结果方法时出现数据库错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42569574/

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