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.

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.