【发布时间】:2021-10-06 06:52:09
【问题描述】:
目前我正在尝试从我的数据中检索特定时间范围内的所有条目。为此,我在模型类中有一个方法,其中包含以下语句:
public function get_records_all($st_date,$end_date){
$sql = SELECT
*
FROM `crm_listings`
WHERE added_date BETWEEN '" . $st_date . "' AND '".$end_date."'
ORDER BY `added_date` DESC;
$response = $this->db->query($sql);
echo $response;
}
在我的控制器类中,我使用以下语句来显示输出:
function fetch_status(){
$startDate = '';
$endDate = '';
$this->load->model('crm/user_model');
if($this->input->post('startDate')){
$startDate = $this->input->post('startDate');
}
if($this->input->post('endDate')){
$endDate = $this->input->post('endDate');
}
$data_all = $this->user_model->get_records_all($startDate,$endDate);
}
但这给了我以下错误:
【问题讨论】:
-
echo $response;期望只回显一个字符串,您的响应不会是一个。我认为您想返回回复而不是return $response;。 -
@NigelRen 好的,所以我将其更改为返回 $response 并在我的控制器类中添加了 echo $data_all,但我仍然遇到同样的错误
-
@JayModi 为什么 CI 有查询生成器时使用原始查询?
-
为什么我们的SQL变量的内容没有引号?
标签: php mysql codeigniter