This is the source, the important thing is I have set_time_limit on every execution of the while loop.
<head>
<title>Update Product</title>
</head>
<body>
<h4>Update Product</h4>
<?
if ($update != "") {
// to be done: backup the old copy of products.csv?
// upload the updated product csv file
if ($userfile_name != "") {
$upload = new upload();
echo $userfile_name . " was uploaded.<br><br>";
$csv_file = $userfile_name;
} else {
echo "No file was uploaded.<br><br>";
echo "products.csv is used.<br><br>";
$csv_file = "products.csv"; // is this the confirmed file name?
}
// delete old records from product table
// and use the updated product csv file to update the product table
if ($csv_file != "") {
$arrs = file($csv_file);
$entryNum = 0;
//set_time_limit(10000);
while (list($number, $body) = each($arrs)) {
set_time_limit(10000);
$pieces = explode("~", $body);
if (sizeof($pieces) != 5) {
echo "Error: Incomplete product record in line number: " . ($entryNum + 1) . "<br>";
$product->delete();
echo "Product table was not updated.";
exit;
}
$prd_id = $pieces[1];
$prd_name = $pieces[2];
// explode the product full name to product name and color/size option
$prd_name_colorsize = explode("(", trim($prd_name));
if (sizeof($prd_name_colorsize) == 2) {
$prd_name = $prd_name_colorsize[0];
$prd_color_size_option = substr($prd_name_colorsize[1], 0, strlen($prd_name_colorsize[1]) - 1);
} else {
$prd_color_size_option = "";
}
if ($pieces[3] == "") {
$pieces[3] = 0;
}
$prd_price = $pieces[3];
$prd_cat_id = $pieces[0];
$prd_name = trim($prd_name);
// check whether there is already an associated product group for the product
// if yes, update the price and category id of the product group if necessary
// if no, create a new product group for that product
$link = mysql_pconnect($sysDBHost, $sysDBUsername, $sysDBPassword);
mysql_select_db($sysDBName, $link);
$sql = "SELECT * FROM product_group WHERE prd_grp_name = '" . trim($prd_name) . "'";
$result = mysql_query($sql, $link);
$result_array = mysql_fetch_array($result);
if (mysql_num_rows($result) > 0) {
if ($result_array[4] != $prd_price ||
$result_array[3] != $prd_cat_id) {
$sql = "UPDATE product_group " .
" SET prd_grp_id = " . $result_array[0] . ", " .
" prd_grp_name = '" . $result_array[1] . "', " .
" prd_grp_description = '" . $result_array[2] ."', " .
" prd_grp_category_id = '" . $prd_cat_id . "', " .
" prd_grp_price = " . $prd_price . ", " .
" prd_grp_weight = " . $result_array[5] . ", " .
" prd_grp_image_thumbnail = '" . $result_array[6] . "', " .
" prd_grp_image_fullsize = '" . $result_array[7] . "', " .
" prd_grp_on_special = '" . $result_array[8] . "', " .
" prd_grp_on_special_price = " . $result_array[9] . ", " .
" prd_grp_product_link = '" . $result_array[10] . "', " .
" prd_grp_size_chart_link = '" . $result_array[11] . "' " .
"WHERE prd_grp_id = " . $result_array[0] . " ";
mysql_query($sql, $link);
}
if ($result_array[2] == "" ||
$result_array[5] == "" ||
$result_array[6] == "" ||
$result_array[7] == "") {
$prd_online = "N";
} else {
$prd_online = "Y";
}
} elseif (mysql_num_rows($result) == 0) {
$sql = "INSERT INTO product_group " .
" ( prd_grp_name, " .
" prd_grp_description, " .
" prd_grp_category_id, " .
" prd_grp_price, " .
" prd_grp_weight, " .
" prd_grp_image_thumbnail, " .
" prd_grp_image_fullsize, " .
" prd_grp_on_special, " .
" prd_grp_on_special_price, " .
" prd_grp_product_link, " .
" prd_grp_size_chart_link " .
" ) VALUES ( '" . $prd_name . "', " .
" '', " .
" '" . $prd_cat_id . "', " .
" " . $prd_price . ", " .
" 0, " .
" 'DEFAULT-SM.gif', " .
" 'DEFAULT.gif', " .
" 'N', " .
" 0, " .
" '', " .
" '' " .
" ) ";
mysql_query($sql, $link);
$prd_online = "N";
}
$sql = "SELECT * FROM product_group WHERE prd_grp_name = '" . trim($prd_name) . "'";
$result = mysql_query($sql, $link);
$result_array = mysql_fetch_array($result);
$sql = "INSERT INTO product " .
" ( prd_id, " .
" prd_group_id, " .
" prd_color_size_option, " .
" prd_online " .
" ) VALUES ( '" . $prd_id . "', " .
" " . $result_array[0] . ", " .
" '" .$prd_color_size_option . "', " .
" '" . $prd_online . "' " .
" ) ";
mysql_query($sql, $link);
$entryNum++;
}
echo "Total product record inserted into product table: " . $entryNum ."<br><br>";
}
exit;
}
?>
<form method="post" action="product_update.php3" enctype="multipart/form-data">
<table width=450 border=0>
<tr>
<td>
Please locate the product csv file:
<input type="hidden" name="MAX_FILE_SIZE" value="10000000">
<input type="file" name="userfile">
<input type="submit" name="update" value="Update">
</td>
</tr>
</table>
</form>
</body>