Okay this is a bit of a logic problem and my brain wont let me work it out right now 🙂
Okay i have a database with a bunch of records with varying dates from six months to approx 5 years. I want to send a few notices to all the records approaching 5 years old (one at six months till 5years old, one at 3 months, 2 months, 1 month and then 1 when it is over 5 years old). Because i only want to send them one notice per time period, i gave their db record a counter which updates every time a notice is sent out.
I'm basing my query on if the record is between the two dates (ie. between six and 3 months till 5 years old) and if it has the counter less than what it should be if the notice for that time frame has been sent out.
The problem i am having with this method is if no notices are sent out due to admin lazyness or vacation or whatever and a few of the records slip into the next time period they arent going to be picked up by the query. ie. a record has 3 months and 1 day until it reaches 5 years old, and the counter says it hasnt gotten its 3 month notification yet. In two days it will slip into the 2 months till 5 years category but now it will dissapear from the query because its counter hasnt updated.
here is the query to select all records that need a notification sent
$result = mysql_query("SELECT * FROM main WHERE (filedate < '".date("Y-m-d",strtotime("-4 years -6 months"))."' and filedate > '".date("Y-m-d",strtotime("-4 years -9 months"))."' and reminder = '0') or (filedate < '".date("Y-m-d",strtotime("-4 years -9 months"))."' and filedate > '".date("Y-m-d",strtotime("-4 years -10 months"))."' and reminder = '1') or (filedate < '".date("Y-m-d",strtotime("-4 years -10 months"))."' and filedate > '".date("Y-m-d",strtotime("-4 years -11 months"))."' and reminder = '2') or (filedate < '".date("Y-m-d",strtotime("-4 years -11 months"))."' and filedate > '".date("Y-m-d",strtotime("-5 years"))."' and reminder = '3') or (filedate <= '".date("Y-m-d",strtotime("-5 years"))."' and reminder = '3') LIMIT 0, $limit", $link) or die (mysql_error());
Thanks in advance,
emrys