php - MySQL get data older than 30 minutes and perform some tasks -
i trying make coupon system, got stuck something. want make function gets data coupon_session time (datetime) older 30 minutes. each of results, want fetch "code" row, , after want delete row.
i've figured out how retrieve data, rest kinda hard me. guys bit?
this code fetching > 30 min old rows:
mysql_query("get * `coupon_session` timestampdiff(minute,time,now()) > 30");
the code fetch want is:
select cs.code coupon_session cs time < date_sub(now(), interval 30 minute);
deleting problem, because value of now()
changes. have several choices, such as:
- get list of ids delete in application , delete (probably safest method).
- calculate "now" in application , use same value
select
,delete
(also safe). - calculate maximum time returned
select
, use subsequent delete.
Comments
Post a Comment