tgavin
asked on
loop equation needed!
I can't get my head around how to write this.
I'm sending email batches, let's say 100 at a time out of 500 total. I already have the process in place to do this, but I don't know how to transcribe what I want to print to the screen.
Basically, on the first loop I want to say "Batch number 1 completed. 100 emails sent. 400 remaining"
On the second loop, "Batch number 2 completed. 200 emails sent. 300 remaining"
And so on.
$count = 0;
$precount = 500;
$queue_size = 100;
$queue_refresh = 25;
$query = mysql_query("SELECT queue_email FROM send_queue LIMIT $queue_size") or die(mysql_error());
while($row = mysql_fetch_assoc($query)) {
// determine number of emails at the start of each batch
$count = mysql_result(mysql_query(" SELECT COUNT(*) as Num FROM send_queue"),0);
// build each address
$to = $row['queue_email'];
// send the email
email_html();
// check for success or failure
if($sent) { // success
// mail sent, remove addresses from queue
$delete_query = mysql_query("DELETE FROM send_queue WHERE queue_id = '$row[queue_id]' AND queue_email = '$row[queue_email]'") or die(mysql_error());
// refresh the page and start next batch
echo "<meta http-equiv=\"refresh\" content=\"$queue_refresh;u rl=$_SERVE R['PHP_SEL F'];\">";
} else {
// sending failed
echo $error_msg;
exit;
}
}
Thanks!
I'm sending email batches, let's say 100 at a time out of 500 total. I already have the process in place to do this, but I don't know how to transcribe what I want to print to the screen.
Basically, on the first loop I want to say "Batch number 1 completed. 100 emails sent. 400 remaining"
On the second loop, "Batch number 2 completed. 200 emails sent. 300 remaining"
And so on.
$count = 0;
$precount = 500;
$queue_size = 100;
$queue_refresh = 25;
$query = mysql_query("SELECT queue_email FROM send_queue LIMIT $queue_size") or die(mysql_error());
while($row = mysql_fetch_assoc($query))
// determine number of emails at the start of each batch
$count = mysql_result(mysql_query("
// build each address
$to = $row['queue_email'];
// send the email
email_html();
// check for success or failure
if($sent) { // success
// mail sent, remove addresses from queue
$delete_query = mysql_query("DELETE FROM send_queue WHERE queue_id = '$row[queue_id]' AND queue_email = '$row[queue_email]'") or die(mysql_error());
// refresh the page and start next batch
echo "<meta http-equiv=\"refresh\" content=\"$queue_refresh;u
} else {
// sending failed
echo $error_msg;
exit;
}
}
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
tgavin: your delete query should look like this:
$delete_query = mysql_query("DELETE FROM send_queue WHERE queue_id = '".$row['queue_id']."' AND queue_email = '".$row['queue_email']."'" ) or die(mysql_error());
$delete_query = mysql_query("DELETE FROM send_queue WHERE queue_id = '".$row['queue_id']."' AND queue_email = '".$row['queue_email']."'"
ASKER
Thank you very much. That's just what I was looking for! :)
$count = (!isset($_GET['count']))? 1 : $_GET['count'];
$precount = 500;
$queue_size = 100;
$queue_refresh = 25;
$totalCount = $precount/$queue_size;
echo "Run number $count <br>". ($totalCount-$count). " ramining<br>" ;
//
//
// do your code
if ($count<$totalCount)
echo "<script>
location.href=\"sendMail.p
</script>";
else
echo "DONE";
?>