在我的模型类中,我首先使用如下查询。
$query = $this->db->query("SELECT * FROM todaywork WHERE idEmployee = $user")
但现在我想将数据过滤作为当前日期。我使用了' curdate()'为了这。在wamp服务器我得到了我想要的结果。但是在将它放到同一个地方的模型类之后,我无法获得数据。有什么问题?
$query = $this->db->query("SELECT * FROM todaywork WHERE idEmployee = $user AND T_date = CURDATE()")
在这里我用js函数去控制器类。这是我的js函数
$.ajax({
type: 'post',
url: 'today_list',
data: {},
success: function (data) {
alert(data);
var result = JSON.parse(data);
var datas = [];
for (var x = 0; x < result.length; x++) {
datas.push('<tr id="list2' + x + '">'
+ '<td hidden="true">' + result[x].idCustomer+ '</td>'
+ '<td>' + result[x].C_name + '</td>'
+ '<td>' + result[x].F_itemname + '</td>'
+ '<td align="center">' + result[x].C_trdate + '</td>'
+ '<td align="center">' + result[x].C_trgrossrental + '</td>'
+ '<td align="center">'
+ '</td>'
+ '<td align="center">'
+ '<input type="button" class="btn btn-warning " value="view">'
+ '</td>'
+ '</tr>');
}
$("#today_work").html(datas+"");
//alert(datas);
},
error: function(data){
alert('error');
}
});
}
然后我的控制器类将是
public function today_list(){
$this->load->model('todayWork/todayWork_model');
try{
echo json_encode($this->todayWork_model->treport_getall());
}
catch(Exception $exc){
return $exc->getTraceAsString();
}
}
这直接到我的模型函数,它从我的数据库中返回数据
function treport_getall()
{
$user = $this->session->userdata['id'];
//**********************************************
try {
$query = $this->db->query("SELECT * FROM todaywork WHERE idEmployee = $user");
if ($query->num_rows() > 0)
{
$row = $query->row();
$from = $row->T_frange;
$to = $row->T_trange;
$note = $row->T_note;
}
$this->db->select("cus.idCustomer,cus.C_name,f.F_itemname,ctr.*");
//$whereCondition = array('cus.idCustomer' => $_POST['custId']);
$this->db->where('C_trnoofarr >', $from);
$this->db->where('C_trnoofarr <', $to);
//filter where
$this->db->from('customer cus');
$this->db->join('contracts AS ctr', 'cus.idCustomer = ctr.idCustomer', 'INNER');
$this->db->join('facility AS f','ctr.idContracts = f.idContracts','INNER');
$query = $this->db->get();
return $query->result();
} catch (Exception $exc) {
return $exc->getTraceAsString();
}
}
在我使用当前日期之前,我得到了我想要的结果。但是在where子句中添加当前日期后我得到错误我把错误函数放在js文件中。我怎么解决我的问题?请帮帮我。