Page 1 of 1
cron to send 5 mails per minute
Posted: Wed Jun 18, 2008 3:07 am
by kkonline
Hi,
I want to use cron tab to send 5 mails per minute(the time part can be adjusted using cron that's not the issue)
but when i write the query as:
PHP Code:
SELECT * FROM invites WHERE `invitation` = 0 AND `email` LIKE '%@gmail.com%' OR `email` LIKE '%@yahoo.%' LIMIT 0,5
it always selects the same first 5 emails.
basically i want after every cron run the next 5 emails should be sent mail. How to adjust this using the above query?
Re: cron to send 5 mails per minute
Posted: Wed Jun 18, 2008 3:35 am
by onion2k
When the mail is sent have another query update the value of 'invitation' to something other than 0.
Re: cron to send 5 mails per minute
Posted: Wed Jun 18, 2008 4:15 am
by helraizer
Something like:
Code: Select all
$sql = "SELECT * FROM invites WHERE `invitation` = 0 AND `email` LIKE '%@gmail.com%' OR `email` LIKE '%@yahoo.%' LIMIT 0,5"
$result = mysql_query($sql) or die("Error in sql: ".mysql_error());
$count = mysql_num_rows($result);
if($count == 5) { // all five were selected
$sqla = "UPDATE `invites` SET `invitation` = 1 WHERE `invitation` = 0 AND `email` LIKE '%@gmail.com%' OR `email` LIKE '%@yahoo.%' LIMIT 0,5";
$resulta = mysql_query($sqla) or die("Error in sqla: ".mysql_error());
} else {
die("error");
}
That basically says, if it selects the first 5 successfully based on your query the it updates the invitation field to Yes or 1. This means that they won't be selected again; it will then go onto the second set of 5 and do the same, etc.
Sam
Re: cron to send 5 mails per minute
Posted: Wed Jun 18, 2008 4:38 am
by kkonline
onion2k wrote:When the mail is sent have another query update the value of 'invitation' to something other than 0.
I am doing the same thing with invitation = 0 after the mail is sent the invitation is made 1
but when i write the query and limit it to 0,5 it selects the same emails again and again
Re: cron to send 5 mails per minute
Posted: Wed Jun 18, 2008 4:46 am
by onion2k
kkonline wrote:onion2k wrote:When the mail is sent have another query update the value of 'invitation' to something other than 0.
I am doing the same thing with invitation = 0 after the mail is sent the invitation is made 1
but when i write the query and limit it to 0,5 it selects the same emails again and again
Ah.. it's your SQL..
If we rewrite it slightly..
Code: Select all
SELECT *
FROM invites
WHERE 1
AND `invitation` = 0
AND `email` LIKE '%@gmail.com%'
OR `email` LIKE '%@yahoo.%'
LIMIT 0,5
Each part of the where clause is separate. So it's selecting everything where invitation is 0 and email is like gmail, or where email is like yahoo... the invitation bit isn't applied if the email is yahoo. You need some brackets...
Code: Select all
SELECT *
FROM invites
WHERE 1
AND `invitation` = 0
AND (`email` LIKE '%@gmail.com%' OR `email` LIKE '%@yahoo.%' )
LIMIT 0,5