2013-12-11 27 views
0

我想獲取基於用戶輸入年齡(整數)的人的詳細信息。現在,只要我執行下面的代碼,我的查詢總是返回空Array()。我沒有指定$postdata陣列。你可以看到我用$postdata['ageto']$postdata['agefrom']在計算$agefrom$agetoCodeginiter 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變量沒有問題。我不確定我做錯了什麼。有人能幫我嗎。

+1

我想你可以檢查你的sql命令。你可以看看這個網站。 http://stackoverflow.com/questions/6142099/how-to-print-sql-statement-in-codeigniter-model – lighter

+0

謝謝打火機..我現在得到了一個線索。它與POST數據的問題 – vkrams

回答

2

我想你必須指定DOB屬於哪個表,就像a.dob。對不起,但我無法發表評論。希望這可以幫助。

0

選擇字段應該添加的表名

$this->db->select('a.uacc_id, a.uacc_username, a.name....); // example

和你where添加的表名了。

$this->db->where('b.dod >= ', $agefrom); // example

,或者您可以輸出的SQL命令。

你可以看看here

+0

將對象名稱添加到列沒有發現差異 – vkrams