Rom*_*man 2 php mysql codeigniter
我想构建一个类似的查询
SELECT username from users
WHERE login_attempts > 3 AND last_attempt_time < 24 (hours).
Run Code Online (Sandbox Code Playgroud)
我有2个问题来构建上述查询.
我在DATETIME格式的last_attempt_time中存储日期(2011-06-16 10:29:23)我可以直接选择从现在起不到24小时的时间差的行吗?(或者我必须选择一行,然后检查PHP的时差吗?)
如何使用CodeIgniter Active Record编写此查询?(我需要使用get_where吗?)我在他们的文档中找不到任何相关的例子.
谢谢.
Fra*_*nes 10
试试这个:
$this->db->select('username');
$this->db->from('users');
$this->db->where('login_attempts >', 3);
$this->db->where('last_attempt_time <', date('Y-m-d H:i:s', strtotime('-24 hours')));
$query = $this->db->get();
Run Code Online (Sandbox Code Playgroud)
您可以在此处找到完整的文档:http://codeigniter.com/user_guide/database/active_record.html#select.