通过 Mysql 查询后无法检索状态计数
Unable to retrieve status count after passing Mysql query
目前我正在使用 CodeIgniter 来检索我在特定时间范围内的数据。所有这些条目都有一个状态。我正在尝试计算特定时间范围内存在的所有数据。目前这是我的模型 class,其中我有以下条目 return 特定日期范围内的所有条目:
public function get_records($st_date,$end_date){
$this->db->select('*');
$this->db->from('crm_listings');
$this->db->where('cast(added_date as date) BETWEEN "' . $st_date . '" AND "' . $end_date . '" AND status= "D"');
return $this->db->count_all_results();
}
还有我的控制器class:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
class Testcontroller extends CI_Controller
{
public function index()
{
$this->load->view('crm/test');
}
function fetch_status(){
$output ='';
$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 = $this->user_model->get_records($startDate,$endDate);
$output .= '
<div class="table-responsive">
<table class="table table-bordered table-striped">
<tr>
<th>Draft</th>
</tr>
';
if($data->num_rows() > 0)
{
$output .= '
<tr>
<td>'.$data.'</td>
</tr>
';
}
else
{
$output .= '<tr>
<td colspan="7">No Data Found</td>
</tr>';
}
$output .= '</table>';
echo $output;
}
}
?>
现在,当我在 $data 之后评论我的控制器 class 中的所有内容并只做一个声明时 echo $data;
我得到了我想要的输出。但是当我将它包裹在 <td>'.$data.'</td>
周围时,它没有给出输出。
在第 echo $this->db->count_all_results();
行编辑函数
function get_records($st_date,$end_date){
echo $this->db->count_all_results();// change this code
// to
return $this->db->get();
}
为了确保有任何数据,请在调用 method/function
之后尝试 print_r($data)
$data = $this->user_model->get_records($startDate,$endDate);
print_r($data) // check data
目前我正在使用 CodeIgniter 来检索我在特定时间范围内的数据。所有这些条目都有一个状态。我正在尝试计算特定时间范围内存在的所有数据。目前这是我的模型 class,其中我有以下条目 return 特定日期范围内的所有条目:
public function get_records($st_date,$end_date){
$this->db->select('*');
$this->db->from('crm_listings');
$this->db->where('cast(added_date as date) BETWEEN "' . $st_date . '" AND "' . $end_date . '" AND status= "D"');
return $this->db->count_all_results();
}
还有我的控制器class:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
class Testcontroller extends CI_Controller
{
public function index()
{
$this->load->view('crm/test');
}
function fetch_status(){
$output ='';
$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 = $this->user_model->get_records($startDate,$endDate);
$output .= '
<div class="table-responsive">
<table class="table table-bordered table-striped">
<tr>
<th>Draft</th>
</tr>
';
if($data->num_rows() > 0)
{
$output .= '
<tr>
<td>'.$data.'</td>
</tr>
';
}
else
{
$output .= '<tr>
<td colspan="7">No Data Found</td>
</tr>';
}
$output .= '</table>';
echo $output;
}
}
?>
现在,当我在 $data 之后评论我的控制器 class 中的所有内容并只做一个声明时 echo $data;
我得到了我想要的输出。但是当我将它包裹在 <td>'.$data.'</td>
周围时,它没有给出输出。
在第 echo $this->db->count_all_results();
function get_records($st_date,$end_date){
echo $this->db->count_all_results();// change this code
// to
return $this->db->get();
}
为了确保有任何数据,请在调用 method/function
之后尝试print_r($data)
$data = $this->user_model->get_records($startDate,$endDate);
print_r($data) // check data