Jump to content

help with this code - all products getting updated?


bidntrade

Recommended Posts

can someone tell me why this code update every products price

even when it has not changed ?

 

$link = mysql_connect($mysqlHost, $user, $password) or die('Could not
connect: ' . mysql_error());
//$handle = fopen("DataFeed.csv", "r");

$handle = fopen("DataFeed.csv", "r");


mysql_select_db($database, $link);


// loop content of csv file, using comma as delemiter
while (($data = fgetcsv($handle)) !== FALSE) {

$id = (int) $data[0];
$orgprice = floatval($data[2]);
$weight = floatval($data[15]);
$qty = floatval($data[8]);

if($orgprice <= 4) { 
$price = ($orgprice * 3);
}else if ($orgprice <= 10) {
$price = ($orgprice * 2);
}else if ($orgprice <= 35) {
$price = ($orgprice / 0.70);
}else if ($orgprice <= 45) {
$price = ($orgprice / 0.76);
}else if ($orgprice <= 150) {
$price = ($orgprice / 0.80);
}else if ($orgprice <= 250) {
$price = ($orgprice / 0.83);
}else{
$price = ($orgprice / 0.85);
}

$price = round($price, 2);



$query = 'SELECT cscart_products.product_id FROM cscart_products LEFT JOIN cscart_product_prices USING (product_id) WHERE product_id = ' . $id . ' AND weight = ' . $weight . ' AND price != ' . $price;


if ($result = mysql_query($query)) {

if($go){
// entry exists update
if(mysql_query("UPDATE cscart_product_prices PP LEFT JOIN cscart_products PI USING (product_id) SET PP.price = '$price', PI.amount = '$qty' WHERE PI.product_code = '$id' AND PI.weight = '$weight'")){
$emailinfo .= "Product ".$id." Price Updated To ".$price. " Stock= " . $qty . " .\n";
echo "Product ".$id." Price Updated To ".$price. " Stock= " . $qty . " .<br>";
}
}
}

$result = "";
$go='1';

}

fclose($handle);
mysql_close($link);

 

 

I have it doing a select and comparing price in database with new price....

but for some reason it updates all of them every time even when there is no need....

 

some of the prices after using the round function are showing as

 

9.5

and my database actually has 9.50

 

is this the reason ?

 

are there a better way to do this ....

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.