DATE介于和LIMIT之间的Codeginiter JOIN查询不起作用


Codeginiter JOIN query with DATE between and LIMIT not working

我正试图根据用户输入的年龄(Integer)获取人员的详细信息。现在,每当我执行下面的代码时,我的查询总是返回null Array()。我还没有指定$postdata数组。你可以看到我使用了$postdata['ageto']$postdata['agefrom']来计算$agefrom$ageto

        $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变量没有问题。我不确定我做错了什么。有人能帮我吗?

我想你必须像a.DOB一样指定DOB属于哪个表。很抱歉收到这篇文章,但我无法发表评论。希望这能有所帮助。

选择字段应添加表名

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

以及您的where添加表名称。

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

或者您可以输出sql命令。

您可以在此处查看