hyeteck Posted February 14, 2007 Share Posted February 14, 2007 hey guys. I have a program that i wrote in java(only language i know) to update products in my MySQL database based on a flat file provided by my supplier. It would take 25 minutes to run the program which was verry verrry slow. So i figured i'de look online for some tutorials and try to write it in PHP and maybe have better luck with that but i think my php file has an error. I was able to rewrite the program in PHP but its not executing completely i believe. here is my code....it only prints the first timestamp and doesn't print the last time stamp and the "Done" message. <?php print date("h:i:s A"); include "db_conn.php"; $handle = @fopen("products.txt", "r"); if ($handle) { $buffer = fgets($handle, 4096); while (!feof($handle)) { $buffer = fgets($handle, 4096); $chunks = explode(" ", $buffer); $prodId = $chunks[0]; $prodPrice = $chunks[1]; $prodMap = $chunks[2]; $prodQuant = $chunks[3]; if($prodMap > 0) { $prodPrice = $prodMap; $prodPrice = floor($prodPrice); $prodPrice = $prodPrice + 0.99; } else { if($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 < 100) $prodPrice = $prodPrice + ($prodPrice * .06); else $prodPrice = $prodPrice + ($prodPrice * .045); $prodPrice = floor($prodPrice); $prodPrice = $prodPrice + 0.99; } $result = mysql_query("UPDATE products SET pPrice=$prodPrice, pInStock=$prodQuant WHERE pID=$prodId"); } fclose($handle); } print date("h:i:s A"); echo "Done!"; ?> each line in my products.txt file containts information for only 1 product. Link to comment https://forums.phpfreaks.com/topic/38439-solved-php-and-mysql-help-file-not-completely-running/ Share on other sites More sharing options...
Greaser9780 Posted February 14, 2007 Share Posted February 14, 2007 Try changing this line: $result = mysql_query("UPDATE products SET pPrice=$prodPrice, pInStock=$prodQuant WHERE pID=$prodId"); To this: $result = mysql_query("UPDATE `products` SET `pPrice`='$prodPrice', `pInStock`='$prodQuant' WHERE `pID`='$prodId' "); Link to comment https://forums.phpfreaks.com/topic/38439-solved-php-and-mysql-help-file-not-completely-running/#findComment-184434 Share on other sites More sharing options...
hyeteck Posted February 14, 2007 Author Share Posted February 14, 2007 Try changing this line: $result = mysql_query("UPDATE products SET pPrice=$prodPrice, pInStock=$prodQuant WHERE pID=$prodId"); To this: $result = mysql_query("UPDATE `products` SET `pPrice`='$prodPrice', `pInStock`='$prodQuant' WHERE `pID`='$prodId' "); wow ..thanks..that fixed it...you are a genius =) i've only had PHP experience since 5pm today and i'm loving every bit of it. The same program that took 25 minutes to run with java on my machine now takes 13 seconds!!! woot woot woot Link to comment https://forums.phpfreaks.com/topic/38439-solved-php-and-mysql-help-file-not-completely-running/#findComment-184439 Share on other sites More sharing options...
Greaser9780 Posted February 14, 2007 Share Posted February 14, 2007 I'm pretty new as well. I just remembered it from a problem I had last week. Glad I could be of some help though. Link to comment https://forums.phpfreaks.com/topic/38439-solved-php-and-mysql-help-file-not-completely-running/#findComment-184444 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.