bidntrade Posted July 4, 2009 Share Posted July 4, 2009 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 .... Quote Link to comment https://forums.phpfreaks.com/topic/164719-help-with-this-code-all-products-getting-updated/ 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.