我想获取基于用户输入年龄(整数)的人的详细信息。现在,只要我执行下面的代码,我的查询总是返回空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