FOR construct error

A

Anonymous

Guest
I have developed a FOR construct to put a delay on my mailing list so as not to time out the server. I believe it is nearly right, but I am getting an error and for the life of me, I do not see where it is. Thaniks to any and all that take the time to look at it. Here is the code

Code:
include_once ("config.php");

for ($i = 1, $hold = 10, set_time_limit(30); $i < $hold; i++, sleep(3)){
//Get emails from db_tbl List
$result = mysql_query("SELECT email FROM db_tble WHERE status = '1'");
if (!$result) {
   echo 'Could not run query: ' . mysql_error();
   exit;
}

else{

$row = mysql_fetch_object($result); 
    echo $row->email;
    mail($row->email, $subject, $message, $headers); 
    
}
}
mysql_free_result($result);
?>

Here is the error Line 129 is for $i = 1, $hold = 10, set_time_limit(30); $i < $hold; i++, sleep(3))

Code:
Parse error: parse error, unexpected T_INC, expecting ')' in /home/myacct/public_html/mailer/APEX_mime.php on line 129
 
the problem is in complexity of your fore statement.. sleep is probably better to use, however it is strongly sidcouraged in all applications, as this would open many pottential problems with your script.

So be carefull while using it..
 
Thanks Guys for your great responses! I googled sleep() and could not find the problems you were talking about. Just a thing about accurracy of the time which is not a big issue to me.

If I just use the sleep function liike this:

Code:
//Get emails from email List
$result = mysql_query("SELECT email FROM db_tble WHERE status = '1'");
if (!$result) {
   echo 'Could not run query: ' . mysql_error();
   exit;
}

while ($row = mysql_fetch_object($result)) {
    echo $row->email;
    mail($row->email, $subject, $message, $headers); 
    
}

mysql_free_result($result);

sleep(10)

?>

and it did not work, it would not permanently mess up something. ie) any problems could be solve by just removing it, right?

Also, I think the problem from the above FOR loop might be with i++ somehow. But I don't know exactly how.

Thanks Greg...[/code]
 
Okay guys... Thankyou very much! I posted the above, and did not get an error. I assume, that because I don't get an error, the code is working. I do not preclude that this is a wrong assumption, but I don't know how to test it so I guess it will have to stand. So, thankyou most sincerely. Greg
 
Back
Top