Jump to content

[SOLVED] PHP and MySQL help, file not completely running..


hyeteck

Recommended Posts

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.

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' ");

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.