目前我正在使用 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 >
<table >
<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>,它不會給出輸出。
uj5u.com熱心網友回復:
在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();
}
為確保有任何資料,請print_r($data)在呼叫該方法/函式后嘗試
$data = $this->user_model->get_records($startDate,$endDate);
print_r($data) // check data
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/315052.html
