Jump to content

Archived

This topic is now archived and is closed to further replies.

tgavin

loop equation needed

Recommended Posts

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 write out 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.

Thanks for any help.

Share this post


Link to post
Share on other sites
umm.. ghetto solution™ !

$count = 1;
for (...) { //for loop that sends email out
//'send email out' script here

echo "Batch number ".$count." completed. ".($count*100) emails sent. ".(500-($count*100))." remaining."
$count++;
}

i was just kidding. that won't REALLY work. if you want it to update live then you will have to use javascript or ajax.

Share this post


Link to post
Share on other sites
Or you could try [man]ob_flush[/man]().

Share this post


Link to post
Share on other sites
[!--quoteo(post=372475:date=May 9 2006, 02:09 AM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ May 9 2006, 02:09 AM) [snapback]372475[/snapback][/div][div class=\'quotemain\'][!--quotec--]
i was just kidding. that won't REALLY work. if you want it to update live then you will have to use javascript or ajax.
[/quote]Actually, that was close :)

The script I have refreshes after each batch is sent, so doing it in PHP is fine. Maybe this will help[code]$count = 0;
$precount = 500;
$queue_size = 100;
$queue_refresh = 25;

$query = mysql_query("SELECT * FROM send_queue LIMIT $queue_size") or die(mysql_error());

if($row_prefs['ignore_abort'] == '1') {
    echo "sending message goes here";
} else {
    echo "sending message goes here";
}

while($row = mysql_fetch_assoc($query)) {
    $count = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM send_queue"),0);
    $to = $row['queue_email'];
    if($sendType == '2') {
        email_html();
        if($sent) {
            // 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());
            echo "<meta http-equiv=\"refresh\" content=\"$queue_refresh;url=send_batch.php\">";
        } else {
        echo $error_msg;
        exit;
        }
    }
}[/code]Thanks for your help!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.