我想獲取基於用戶輸入年齡(整數)的人的詳細信息。現在,只要我執行下面的代碼,我的查詢總是返回空Array()
。我沒有指定$postdata
陣列。你可以看到我用$postdata['ageto']
和$postdata['agefrom']
在計算$agefrom
和$ageto
Codeginiter JOIN查詢之間的日期和極限不工作
$now = new DateTime();
//Converting _POST age to Date
$agefrom = date("Y-m-d",strtotime($now->format("Y")-$postdata['ageto'].'-'.$now->format("m").'-'.$now->format("d")));
$ageto = date("Y-m-d",strtotime($now->format("Y")-$postdata['agefrom'].'-'.$now->format("m").'-'.$now->format("d")));
$this->db->select('uacc_id, uacc_username, name, dob, city, education');
$this->db->from('user_accounts as a');
$this->db->join('personal as b','a.uacc_id = b.pruserid','INNER');
$this->db->join('profession as c','a.uacc_id = c.puserid','INNER');
$this->db->join('location as d','a.uacc_id = d.luserid','INNER');
$this->db->where('dob >= ',$agefrom);
$this->db->where('dob <= ',$ageto);
$this->db->limit(10, $offset);
$query = $this->db->get();
return $query->result();
我一直懷疑我輸入後不能正常獲取數據使用。所以我用我的簡單查詢select * from... where dob >....
取代了它,它運行良好。所以_POST
變量沒有問題。我不確定我做錯了什麼。有人能幫我嗎。
我想你可以檢查你的sql命令。你可以看看這個網站。 http://stackoverflow.com/questions/6142099/how-to-print-sql-statement-in-codeigniter-model – lighter
謝謝打火機..我現在得到了一個線索。它與POST數據的問題 – vkrams