2013-12-11 28 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