hyeteck Posted February 18, 2007 Share Posted February 18, 2007 hey guys. i have a little program i wrote to update price and quantity for products in a database and if the product doesn't exist then it creates it and then updates the price and quantity. It runs but stops after about 15 seconds. It creates about 10 products and then just stops out of nowhere. If i refresh the page it will create another 10 or so products and stop again. I am running this on an empty database so the first time it runs should take a while but after that, it should be quick because most of the products will already be in the database and there will be no need to create new products. the "approved" text file has only price, quantity, and productid info...the "all" text file has all the information for the products. here is my code. Can anyone tell me why it stops after 10-15 seconds? Is there too much information for php to handle?? or is it just my code? both text files have about 16,000 lines of data but the "approved" text file has only 5 columns of data where as the "all" text file has about 30 columns of data. Both are tab delimited text files. <?php print date("h:i:s A"); echo "<br>"; include "../vsadmin/db_conn_open.php"; $dblapproved = @fopen("dbl_approved_items.txt", "r"); if ($dblapproved) { $approved_string = fgets($dblapproved, 4096); while (!feof($dblapproved)) { $approved_string = fgets($dblapproved, 4096); $approved_chunks = explode(" ", $approved_string); $prodId = $approved_chunks[0]; $prodPrice = $approved_chunks[1]; $prodMap = $approved_chunks[2]; $prodQuant = $approved_chunks[3]; //item exists so we just need to update the price and quantity if(mysql_num_rows(mysql_query("SELECT * from `products` WHERE pID='$prodId' "))) { if($prodMap > 0 || $prodMap!= NULL) $prodPrice = $prodMap; elseif($prodPrice < 10) $prodPrice = $prodPrice + ($prodPrice * .50); elseif($prodPrice >= 10 && $prodPrice < 50) $prodPrice = $prodPrice + ($prodPrice * .25); elseif($prodPrice >= 50 && $prodPrice < 150) $prodPrice = $prodPrice + ($prodPrice * .15); elseif($prodPrice >= 150 && $prodPrice < 400) $prodPrice = $prodPrice + ($prodPrice * .10); elseif($prodPrice >= 400 && $prodPrice < 1000) $prodPrice = $prodPrice + ($prodPrice * .06); else $prodPrice = $prodPrice + ($prodPrice * .05); $prodPrice = floor($prodPrice); $prodPrice = $prodPrice + 0.99; $result = mysql_query("UPDATE `products` SET `pPrice`='$prodPrice', `pInStock`='$prodQuant' WHERE `pID`='$prodId' ") or die(mysql_error()); } //item doesn't exist and we need to create it and any necessary categories else { $dblall = @fopen("dbl_all.txt", "r"); if($dblall) { $all_string = fgets($dblall, 4096); while (!feof($dblall)) { $all_string = fgets($dblall, 4096); $all_chunks = explode(" ", $all_string); $temp_string = $all_chunks[0]; if($prodId==$temp_string) { $brand_text = $all_chunks[6]; $brand_logo = $all_chunks[7]; $cat_segment = $all_chunks[8]; $cat_category = $all_chunks[9]; $cat_content = $all_chunks[10]; $prod_name = $all_chunks[11]; $prod_short_desc = $all_chunks[12]; $prod_long_desc = $all_chunks[13]; $prod_upc = $all_chunks[15]; $prod_weight = $all_chunks[19]; $prod_weight = $prod_weight; $prod_image = $all_chunks[20]; if($prod_image==0 || $prod_image==NULL) { $prod_big_image = "prodimages/large/".$prodId.".jpg"; $prod_image = "prodimages/small/".$prodId.".jpg"; } else { $prod_big_image = "prodimages/large/".$prod_image; $prod_image = "prodimages/small/".$prod_image; } //this is where my categoires are made. There are 3 levels of categoires. "Category" is the highest level then there is "Segment" and then //there is "Content". the "Content" section is what holds all the products. $temp_quer = mysql_query("SELECT sectionID from `sections` WHERE sectionName='$cat_content' AND rootSection='1' ") or die(mysql_error()); if(!($cat_array = mysql_fetch_array($temp_quer))) { $temp_quer = mysql_query("SELECT sectionID from `sections` WHERE sectionName='$cat_category' AND rootSection='0' AND topSection!='0' ") or die(mysql_error()); if(!($cat_array = mysql_fetch_array($temp_quer))) { $temp_quer = mysql_query("SELECT sectionID from `sections` WHERE sectionName='$cat_segment' AND topSection ='0' AND rootSection='0' ") or die(mysql_error()); if(!($cat_array = mysql_fetch_array($temp_quer))) { $temp = mysql_query("INSERT INTO `sections`(sectionName, sectionWorkingName, topSection, rootSection) VALUES('$cat_segment', '$cat_segment', '0', '0')") or die(mysql_error()); } $temp_quer = mysql_query("SELECT sectionID from `sections` WHERE sectionName='$cat_segment' AND topSection='0' AND rootSection='0' ") or die(mysql_error()); $cat_array = mysql_fetch_array($temp_quer); $cat_id = $cat_array['sectionID']; $temp = mysql_query("INSERT INTO `sections`(sectionName, sectionWorkingName, topSection, rootSection) VALUES('$cat_category', '$cat_category', '$cat_id', '0')") or die(mysql_error()); } $temp_quer = mysql_query("SELECT sectionID from `sections` WHERE sectionName='$cat_category' AND topSection!='0' and rootSection='0' ") or die(mysql_error()); $cat_array = mysql_fetch_array($temp_quer); $cat_id = $cat_array['sectionID']; $temp = mysql_query("INSERT INTO `sections`(sectionName, sectionWorkingName, topSection, rootSection) VALUES('$cat_content', '$cat_content', '$cat_id', '1')") or die(mysql_error()); } $temp_quer = mysql_query("SELECT sectionID from `sections` WHERE sectionName='$cat_content' AND topSection!='0' AND rootSection='1' ") or die(mysql_error()); $cat_array = mysql_fetch_array($temp_quer); $cat_id = $cat_array['sectionID']; $temp = mysql_query("INSERT INTO `products`(pID, pName, pSection, pDescription, pLongdescription, pImage, pLargeimage, pBrandimage, pBrandtext, pPrice, pWeight, pInStock, pDropship, pUPC) VALUES('$prodId', '$prod_name', '$cat_id', '$prod_short_desc', '$prod_long_desc', '$prod_image', '$prod_big_image', '$brand_image', '$brand_text', '0', '$prod_weight', '0', '1', '$prod_upc')") or die(mysql_error()); } } //update the price and quantity after the product and any necessary categories are made if($prodMap > 0 || $prodMap!= NULL) $prodPrice = $prodMap; elseif($prodPrice < 10) $prodPrice = $prodPrice + ($prodPrice * .50); elseif($prodPrice >= 10 && $prodPrice < 50) $prodPrice = $prodPrice + ($prodPrice * .25); elseif($prodPrice >= 50 && $prodPrice < 150) $prodPrice = $prodPrice + ($prodPrice * .15); elseif($prodPrice >= 150 && $prodPrice < 400) $prodPrice = $prodPrice + ($prodPrice * .10); elseif($prodPrice >= 400 && $prodPrice < 1000) $prodPrice = $prodPrice + ($prodPrice * .06); else $prodPrice = $prodPrice + ($prodPrice * .05); $prodPrice = floor($prodPrice); $prodPrice = $prodPrice + 0.99; $result = mysql_query("UPDATE `products` SET `pPrice`='$prodPrice', `pInStock`='$prodQuant' WHERE `pID`='$prodId' ") or die(mysql_error()); fclose($dblall); } } } fclose($dblapproved); } print date("h:i:s A"); echo "<br>Done!"; ?> Quote Link to comment Share on other sites More sharing options...
fert Posted February 18, 2007 Share Posted February 18, 2007 Can anyone tell me why it stops after 10-15 seconds? Because that's what set in the php.ini Quote Link to comment Share on other sites More sharing options...
hyeteck Posted February 18, 2007 Author Share Posted February 18, 2007 i have another file that runs for about 40 seconds with no problems though. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 18, 2007 Share Posted February 18, 2007 It's either an error or a time out issue. Quote Link to comment Share on other sites More sharing options...
hyeteck Posted February 18, 2007 Author Share Posted February 18, 2007 anyone? i updated the code. tried to to cut it down and make it shorter...especially where it makes the categories. <?php print date("h:i:s A"); echo "<br>"; include "../vsadmin/db_conn_open.php"; $dblapproved = @fopen("dbl_approved_items.txt", "r"); if ($dblapproved) { $approved_string = fgets($dblapproved, 4096); while (!feof($dblapproved)) { $approved_string = fgets($dblapproved, 4096); $approved_chunks = explode(" ", $approved_string); $prodId = $approved_chunks[0]; $prodPrice = $approved_chunks[1]; $prodMap = $approved_chunks[2]; $prodQuant = $approved_chunks[3]; //item exists so we just need to update the price and quantity if(mysql_num_rows(mysql_query("SELECT * from `products` WHERE pID='$prodId' "))) { if($prodMap > 0 || $prodMap!= NULL) $prodPrice = $prodMap; elseif($prodPrice < 10) $prodPrice = $prodPrice * 1.50; elseif($prodPrice >= 10 && $prodPrice < 50) $prodPrice = $prodPrice * 1.25; elseif($prodPrice >= 50 && $prodPrice < 150) $prodPrice = $prodPrice * 1.15; elseif($prodPrice >= 150 && $prodPrice < 400) $prodPrice = $prodPrice * 1.10; elseif($prodPrice >= 400 && $prodPrice < 1000) $prodPrice = $prodPrice * 1.06; else $prodPrice = $prodPrice * 1.05; $prodPrice = floor($prodPrice); $prodPrice = $prodPrice + 0.99; $result = mysql_query("UPDATE `products` SET `pPrice`='$prodPrice', `pInStock`='$prodQuant' WHERE `pID`='$prodId' ") or die(mysql_error()); } //item doesn't exist and we need to create it and any necessary categories else { $dblall = @fopen("dbl_all.txt", "r"); if($dblall) { $all_string = fgets($dblall, 4096); while (!feof($dblall)) { $all_string = fgets($dblall, 4096); $all_chunks = explode(" ", $all_string); $temp_string = $all_chunks[0]; if($prodId==$temp_string) { $brand_text = $all_chunks[6]; $brand_logo = $all_chunks[7]; $cat_segment = $all_chunks[8]; $cat_category = $all_chunks[9]; $cat_content = $all_chunks[10]; $prod_name = $all_chunks[11]; $prod_short_desc = $all_chunks[12]; $prod_long_desc = $all_chunks[13]; $prod_upc = $all_chunks[15]; $prod_weight = $all_chunks[19]; $prod_image = $all_chunks[20]; if($prod_image==0 || $prod_image==NULL) { $prod_big_image = "prodimages/large/".$prodId.".jpg"; $prod_image = "prodimages/small/".$prodId.".jpg"; } else { $prod_big_image = "prodimages/large/".$prod_image; $prod_image = "prodimages/small/".$prod_image; } //this is where my categoires are made. There are 3 levels of categoires. "Category" is the highest level then there is "Segment" and then //there is "Content". the "Content" section is what holds all the products. //$temp_quer = mysql_query("SELECT sectionID from `sections` WHERE sectionName='$cat_content' AND rootSection='1' ") or die(mysql_error()); if((mysql_num_rows(mysql_query("SELECT sectionID from `sections` WHERE sectionName='$cat_content' AND rootSection='1' ")))==0) { if((mysql_num_rows(mysql_query("SELECT sectionID from `sections` WHERE sectionName='$cat_category' AND rootSection='0' AND topSection!='0' ")))==0) { if((mysql_num_rows(mysql_query("SELECT sectionID from `sections` WHERE sectionName='$cat_segment' AND topSection ='0' AND rootSection='0' ")))==0) { $temp = mysql_query("INSERT INTO `sections`(sectionName, sectionWorkingName, topSection, rootSection) VALUES('$cat_segment', '$cat_segment', '0', '0')") or die(mysql_error()); } $temp_quer = mysql_query("SELECT sectionID from `sections` WHERE sectionName='$cat_segment' AND topSection='0' AND rootSection='0' ") or die(mysql_error()); $cat_array = mysql_fetch_array($temp_quer); $cat_id = $cat_array['sectionID']; $temp = mysql_query("INSERT INTO `sections`(sectionName, sectionWorkingName, topSection, rootSection) VALUES('$cat_category', '$cat_category', '$cat_id', '0')") or die(mysql_error()); } $temp_quer = mysql_query("SELECT sectionID from `sections` WHERE sectionName='$cat_category' AND topSection!='0' and rootSection='0' ") or die(mysql_error()); $cat_array = mysql_fetch_array($temp_quer); $cat_id = $cat_array['sectionID']; $temp = mysql_query("INSERT INTO `sections`(sectionName, sectionWorkingName, topSection, rootSection) VALUES('$cat_content', '$cat_content', '$cat_id', '1')") or die(mysql_error()); } $temp_quer = mysql_query("SELECT sectionID from `sections` WHERE sectionName='$cat_content' AND topSection!='0' AND rootSection='1' ") or die(mysql_error()); $cat_array = mysql_fetch_array($temp_quer); $cat_id = $cat_array['sectionID']; $temp = mysql_query("INSERT INTO `products`(pID, pName, pSection, pDescription, pLongdescription, pImage, pLargeimage, pBrandimage, pBrandtext, pPrice, pWeight, pInStock, pDropship, pUPC) VALUES('$prodId', '$prod_name', '$cat_id', '$prod_short_desc', '$prod_long_desc', '$prod_image', '$prod_big_image', '$brand_image', '$brand_text', '0', '$prod_weight', '0', '1', '$prod_upc')") or die(mysql_error()); } } //update the price and quantity after the product and any necessary categories are made if($prodMap > 0 || $prodMap!= NULL) $prodPrice = $prodMap; elseif($prodPrice < 10) $prodPrice = $prodPrice * 1.50; elseif($prodPrice >= 10 && $prodPrice < 50) $prodPrice = $prodPrice * 1.25; elseif($prodPrice >= 50 && $prodPrice < 150) $prodPrice = $prodPrice * 1.15; elseif($prodPrice >= 150 && $prodPrice < 400) $prodPrice = $prodPrice * 1.10; elseif($prodPrice >= 400 && $prodPrice < 1000) $prodPrice = $prodPrice * 1.06; else $prodPrice = $prodPrice * 1.05; $prodPrice = floor($prodPrice); $prodPrice = $prodPrice + 0.99; $result = mysql_query("UPDATE `products` SET `pPrice`='$prodPrice', `pInStock`='$prodQuant' WHERE `pID`='$prodId' ") or die(mysql_error()); fclose($dblall); } } } fclose($dblapproved); } print date("h:i:s A"); echo "<br>Done!"; ?> Quote Link to comment Share on other sites More sharing options...
hyeteck Posted February 18, 2007 Author Share Posted February 18, 2007 hmm..now i am getting this error # You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'S INTEGRATOR KIT', 'Allows Vutech screens to use standard po i have no idea what that mens. I don't even have a place in my code where i used the words 'S INTEGRATOR KIT' Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 18, 2007 Share Posted February 18, 2007 There error is in your SQL, not your PHP. Try echo'ing your SQL calls and then find the one that's wrong. Quote Link to comment Share on other sites More sharing options...
hyeteck Posted February 18, 2007 Author Share Posted February 18, 2007 i started printing out the mysql calls one by one. i echoed the first call $result = mysql_query("UPDATE `products` SET `pPrice`='$prodPrice', `pInStock`='$prodQuant' WHERE `pID`='$prodId' ") or die(mysql_error()); echo $result; it prints out the following: # 11111111111111111111111111111111111111111111111111111111111111111111111111111111You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'S INTEGRATOR KIT', 'Allows Vutech screens to use standard po Quote Link to comment Share on other sites More sharing options...
trq Posted February 18, 2007 Share Posted February 18, 2007 Echo the query. eg; <?php $sql ="UPDATE products SET pPrice ='$prodPrice', pInStock='$prodQuant' WHERE pID='$prodId' "; if (!$result = mysql_query($sql)) { echo $sql; } ?> PS; Ive removed all those backticks. Don't know why everyone insists on using them when they are not required. Quote Link to comment Share on other sites More sharing options...
hyeteck Posted February 18, 2007 Author Share Posted February 18, 2007 hmm, i think i fugred it out....it has to do with my text file Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.