【发布时间】:2021-11-26 06:56:05
【问题描述】:
目前我正在使用 CodeIgniter 在特定时间范围内检索我的数据。所有这些条目都有一个状态。我正在尝试计算特定时间范围内存在的所有数据。目前这是我的模型类,其中我有以下条目来返回特定日期范围内的所有条目:
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();
}
还有我的控制器类:
<?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 之后评论我的控制器类中的所有内容并只发表声明 echo $data; 时,我得到了我想要的输出。但是当我将它包裹在 <td>'.$data.'</td> 周围时,它不会给出输出。
【问题讨论】:
标签: php mysql codeigniter