bidntrade Posted July 3, 2009 Share Posted July 3, 2009 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? Link to comment https://forums.phpfreaks.com/topic/164620-help-with-my-code-update-mysql/ Share on other sites More sharing options...
bidntrade Posted July 3, 2009 Author Share Posted July 3, 2009 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 ? Link to comment https://forums.phpfreaks.com/topic/164620-help-with-my-code-update-mysql/#findComment-868186 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.