How to select last 3 minutes' records from MySQL with PHP
this is my SQL table:
+----------------+----------------+-----------+------------------------+
| User_Name | Password | IP | Login_Time |
+----------------+----开发者_Python百科------------+-----------+------------------------+
| rthrthrhrt | fjdjetje5e | 127.0.0.1 | 2011-09-24 18:02:06 |
| Empty | Empty | 127.0.0.1 | 2011-09-24 18:10:01 |
| Empty | Empty | 127.0.0.1 | 2011-09-24 18:04:00 |
| rsyrt | rwytw4364 | 127.0.0.1 | 2011-09-24 18:08:59 |
| eryrjrj5 | Empty | 127.0.0.1 | 2011-09-24 18:03:56 |
| reutreuetry | reuretyre | 127.0.0.1 | 2011-09-24 18:06:53 |
| Empty | rthrtrt | 127.0.0.1 | 2011-09-24 18:05:51 |
| djdjgdjh | 66735 | 127.0.0.1 | 2011-09-24 18:09:49 |
| fgjdgjdhg | Empty | 127.0.0.1 | 2011-09-24 18:07:46 |
| Empty | Empty | 127.0.0.1 | 2011-09-24 18:11:43 |
+----------------+----------------+-----------+------------------------+
I am developing a brute force addon with PHP and MySQL. I would like to select last 3 minutes' records.
for example (what i'd like to do?): time is now: 2011-09-26 9:45:00. i would like to select all records between 2011-09-26 9:45:00 and 2011-09-26 9:42:00.
Use this sql query:
select * from myTable where Login_time > date_sub(now(), interval 3 minute) ;
This query will work even if your table is not updated...
select * from myTable where Login_time > select max(time) - interval 3 minute ;
精彩评论