Forum Moderators: coopster
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?
Then, when the email is sent, for those 5 emails it selects, have it update each row and set those 5 to "1" for the "been_emailed" field.
Instead of the query you had, run this:
SELECT * FROM invites WHERE `invitation` = 0 & `been_emailed` = 0 AND `email` LIKE '%@gmail.com%' OR `email` LIKE '%@yahoo.%' LIMIT 0,5
Then, the 5 you just sent will not apply since their "been_emailed" field has a value of "1" instead of "0".
Let me know if that works :)
$offset = file_get_contents("my_offset.txt");
Then write the new offset into the file. You can check when you've reached the end of your items by interrogating the number of returned rows, e.g.
if(mysql_num_rows($result)!=5)
{
// Write out offset '0' into
// my_offset.txt to start again or
// mail me and tell me to shut off the
// cron...
}
There's a million ways to keep track of the offset, that's just one. With regard to your current solution, I would make a guess that you have an error in the query that is setting the 'invitation' field to 1 after the mail is sent - that's why you're getting the same results. Hope this helps anyway.