I hate to sound like a nagging old lady, but if you'd designed your database better you wouldn't be coming accross this problem as you'd be able to do it all with one simple query, however, that is not the case so let's address the problem in hand.
Like TTT says, SELECT * is bad, avoid it if you possibly can. How is this script being run (called through a browser, run from the command line)? What indexs do you have on the table? I'll assume that it's being run in such a way that anything directly output (echo/print) is going to be poinless. Now, the big one here is error checking and debuging code. I've re-written below, might not all be necesarry but take a look at the suggestions.
<?php
set_time_limit(0);
mysql_connect("");
mysql_select_db("");
$errors=array();
$debug=false;
$debugs=array();
ini_set("MAX_EXECUTION_TIME", "90000");
//If RO is of type integer you don't need the single quotes around the numbers
$query = "SELECT RO, LABORAMT, MISCAMT, PARTAMT FROM LUTHERSELLANDRECOMMEND WHERE (RO BETWEEN '1278519' AND '1282183')";
if(!$result = mysql_query($query)) {
$errors[]="SQL: $query\nERROR: ".mysql_error();
} elseif($debug==true) {
$debugs[]="SQL: $query";
}
while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$ro = $row["RO"];
//no faster just I find it a little less cluttered, personal preference really
//except for the replacement of preg_split with explode. As a rule, if you don't need the power of
//regular expressions, don't use them
$labor = array_sum(explode(' ',$row['LABORAMT']));
$misc = array_sum(explode(' ',$row['MISCAMT']));
$parts = array_sum(explode(' ',$row['PARTAMT']));
$total = $labor + $misc + $parts;
if($debug==true) {
$debugs[]="labor: $labor - misc: $misc - parts: $parts - total: $total";
}
$query1 = "UPDATE LUTHERSELLANDRECOMMEND SET ROTOTAL ='$total' WHERE RO='$ro'";
if(!$result1 = mysql_query($query1)) {
$errors[]="SQL: $query1\nERROR: ".mysql_error();
} elseif($debug==true) {
$debugs[]="SQL: $query1";
}
}
$subject = "Luther Selland Recommended Totals was Completed!";
$body = "
<HTML><HEAD><TITLE></TITLE>
<META http-equiv=Content-Type content='text/html; charset=iso-8859-1'>
<META content='MSHTML 6.00.2800.1170' name=GENERATOR></HEAD>
<BODY bgColor=D8D8D9 text='#FFFFFF' leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>";
if(count($debugs)>0) {
$body.="DEBUG MESSAGES\n\n";
for($i=0;$i<count($debugs);$i++) {
$body.=$debugs[$i]."\n";
}
}
if(count($errors)>0) {
$body.="ERROR MESSAGES\n\n";
for($i=0;$i<count($errors);$i++) {
$body.=$errors[$i]."\n";
}
}
$body.="\n\nLuther Selland Recommended Totals was Completed!
</body>
</html>";
mail("support@mindwerk.com",
$subject,
$body,
"From: Quality Assurance <sales@qualityassure.net>\n" .
"To: \n" .
"MIME-Version: 1.0\n" .
"Content-type: text/html; charset=iso-8859-1");
?>
HTH
Bubbble