0

I have a table "login_attempts" with the fields: id, ip, login_name, time.

I want to achieve this:

Count the number of occurrences for the last 10 minutes for a particular login_name.

I'd like to know the query statement in CodeIgniter's active records format?

4

1 回答 1

0
$this->db->select('COUNT(*) AS count', FALSE);
$this->db->from('login_attempts');
$this->db->where('login_name', $name);
$this->db->where('time > UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 10 MINUTE))', NULL, FALSE);

That assumes your table is set up to use Unix timestamps. If that doesn't work, try:

$this->db->where('time > TIMESTAMP(DATE_SUB(NOW(), INTERVAL 10 MINUTE))', NULL, FALSE);

or:

$this->db->where('time > DATE_SUB(NOW(), INTERVAL 10 MINUTE)', NULL, FALSE);

Let me know if you have trouble.

于 2013-04-22T13:56:31.353 回答