Jump to content

bidntrade

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

bidntrade's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. i have this code .... it does not seem to work ..... I would like to test : product_id and weight when updating to make sure they match my variable . and i would like to test to see if the price has changed . $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'; } go easy on me im very new to php ... as you can tell from the code ... the price variable sometime reads like this 9.5 but my database stores them like 9.50 i would rather not have to do the select and just test if the update matched anything or not with a WHERE clause . but for some reason even if its not there it returns true Note: the code im using this in is going through a csv file one line at a time nightly checking for price changes . there is about 3600 products in the csv. HELP !
  2. 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 ....
  3. the login is from a Form on the webpage the form has 2 input boxes : username password the same supplier has a xml url thats not passworded .. but i dont know how to parse xml files .... but the xml file is 14megs and the csv is 2 megs
  4. problem is : the site owner requires a login to there site to access. no direct link cause its generated dynamically price updates each night ....
  5. I have a site that has a csv feed updated everyday ... I have a script that i use to parse the csv and update my database each day . the problem is i must manually download the csv and upload to my ftp server for the script to work ... now im using : $handle = fopen("DataFeed.csv", "r"); i would like to be able to pull it directly like this $handle = fopen("http://www.sitenamehere.com/Reseller/Feeds/GetDataFeed.asp?type=csv", "r"); that way it could be run automated each night .... the problem is the site requires me to login before i have access to the file download... the site owner said something about : not sure what they was talking about ... are there a way around this ?
  6. also .. I would really like to do the same thing with a xml feed instead of a csv anyone have idea how to do it ?
  7. Need help opening this csv file and updating Mysql ... anyone have anyidea why this code does not work its pulling the data from the csv ok . but the loop for the mysql is not got the correct values. if i echo $list[product_id] they are not correct ids. what do i have wrong here . $link = mysql_connect($mysqlHost, $user, $password) or die('Could not connect: ' . mysql_error()); $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]); if($orgprice <= 10) { $price = ($orgprice / 0.30); }else if ($orgprice <= 50) { $price = ($orgprice / 0.50); }else if ($orgprice <= 100) { $price = ($orgprice / 0.60); }else if ($orgprice <= 300) { $price = ($orgprice / 0.75); }else{ $price = ($orgprice / 0.85); } $query = 'SELECT product_id FROM cscart_products'; if (!$result = mysql_query($query)) { continue; } if ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { // added so i can see the value for testing echo $line[product_id] . "<br>"; $query = "UPDATE cscart_product_prices SET price='$price' WHERE product_id=$line[product_id]"; mysql_query($query); if (mysql_affected_rows() <= 0) { // no rows where affected by update query } } else { // entry don't exists continue or insert... } mysql_free_result($result); } fclose($handle); mysql_close($link); as you can see for some reason when i echo $list[product_code] its the same for every data entry... the number echoed is the same ... why?
×
×
  • 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.