_tina_ Posted December 22, 2009 Share Posted December 22, 2009 I have a script which sends out emails every night at 12am. The problem is that the first and second email are going out together, rather than the first one day and the second the next day. Loop if(id == 1) send email increment id by 1 update database endif if(id == 2) send email increment id by 1 update database endif End Loop This is obviously going to send both the same night as the first if is incrementing the id so the 2nd if will be true. Is there a way around this? I have a "date_modified" field in a MySQL database which is updated after each email is sent. Could I use this somehow to help here? For instance: if (id == 1 & date_modified !> ... ? ) Any help would be appreciated. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/186036-if-date-comparasion/ Share on other sites More sharing options...
aeroswat Posted December 22, 2009 Share Posted December 22, 2009 You say this is supposed to send out two e-mails. So you want like this... on a two day cycle you send email 1 the first day and email 2 the 2nd day. Then the next two days you do the same thing with the same e-mails? And so on and so on? If that loop is going through the people you are sending the email to then yes you will have to store a variable in your database to say which needs to be sent next. If the loop is for the days you can use a mod operator with a count variable like this if(count % 2){ send email2 }else{ send email1 } Link to comment https://forums.phpfreaks.com/topic/186036-if-date-comparasion/#findComment-982406 Share on other sites More sharing options...
ChemicalBliss Posted December 22, 2009 Share Posted December 22, 2009 How are you executing the script? Cron jobs? If the script is executed at exactly midnight, and ytou only want to send a specific amount of emails in that one execution. Thyen logic like this should suffice: Loop (while $loop_count is less than $loop_max) Get Next Row From Mysql (that "Sent" = false) Send Email On Successfull Send, Set Row Field "Sent" = true end Loop Link to comment https://forums.phpfreaks.com/topic/186036-if-date-comparasion/#findComment-982407 Share on other sites More sharing options...
_tina_ Posted December 22, 2009 Author Share Posted December 22, 2009 Thanks for the replies. Yes, I'm sending via a cron job. The problem with a $loop_max variable is I have to send this to thousands of users so I don't know in advance what the max will be. Thanks again for the reply. How are you executing the script? Cron jobs? If the script is executed at exactly midnight, and ytou only want to send a specific amount of emails in that one execution. Thyen logic like this should suffice: Loop (while $loop_count is less than $loop_max) Get Next Row From Mysql (that "Sent" = false) Send Email On Successfull Send, Set Row Field "Sent" = true end Loop Link to comment https://forums.phpfreaks.com/topic/186036-if-date-comparasion/#findComment-982416 Share on other sites More sharing options...
ChemicalBliss Posted December 22, 2009 Share Posted December 22, 2009 loop_max will be the number of emails you want to send that night, you can use a mysql query to count the amount of users if u want to send an email to everyone., but loop_max lets you put a maximum amount of emails to be sent (so u dont get IP banned or suspended or flooding servers or overloading your host.) Link to comment https://forums.phpfreaks.com/topic/186036-if-date-comparasion/#findComment-982420 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.