Jump to content

rseigel

Members
  • Posts

    88
  • Joined

  • Last visited

Everything posted by rseigel

  1. The plot thickens. $handle = fopen("GeneratedList.csv", "r+"); ini_set('auto_detect_line_endings', true); $contents = file('GeneratedList.csv'); $header = 'true'; while (($data = fgetcsv($handle, 100000, ",")) !== FALSE) { if ($header = 'true') { $header = 'false'; break; } $num = count($data); for ($c=0; $c < $num; $c++) { if ($c = 1) { $supplier_reference = $data[($c-1)]; echo $supplier_reference; } if ($c = 2) { $quantity = $data[($c-1)]; echo $quantity; mysql_query("UPDATE stock_available, product SET stock_available.quantity = $quantity WHERE stock_available.id_product = product.id_product AND product.supplier_reference = '$supplier_reference'") or die(mysql_error()); mysql_query("UPDATE stock_available, product_attribute SET stock_available.quantity = $quantity WHERE stock_available.id_product_attribute = product_attribute.id_product_attribute AND product_attribute.supplier_reference = '$supplier_reference'") or die(mysql_error()); } if ($c = 3) { } if ($c = 4) { } } } fclose($handle); I added echos to see what the values were and I get nothing being output. Did I do something silly in the code or is this still a csv issue?
  2. It's almost like mySQL is not recognizing the quantity as a number and isn't updating it. ::::
  3. Crap! When I go back to my regular code: ini_set('auto_detect_line_endings', true); $contents = file('GeneratedList.csv'); $handle = fopen("GeneratedList.csv", "r+"); $header = 'true'; while (($data = fgetcsv($handle, 100000, ",", '"')) !== FALSE) { if ($header = 'true') { $header = 'false'; break; } $num = count($data); for ($c=0; $c < $num; $c++) { if ($c = 1) { $supplier_reference = $data[($c-1)]; } if ($c = 2) { $quantity = $data[($c-1)]; mysql_query("UPDATE stock_available, product SET stock_available.quantity = $quantity WHERE stock_available.id_product = product.id_product AND product.supplier_reference = '$supplier_reference'") or die(mysql_error()); mysql_query("UPDATE stock_available, product_attribute SET stock_available.quantity = $quantity WHERE stock_available.id_product_attribute = product_attribute.id_product_attribute AND product_attribute.supplier_reference = '$supplier_reference'") or die(mysql_error()); } if ($c = 3) { } if ($c = 4) { } } } fclose($handle); It doesn't update the inventory as expected. Any ideas? Thanks, Ron
  4. Wooooohooooo! I just added: ini_set('auto_detect_line_endings', true); $contents = file('GeneratedList.csv'); to the top and the output is now perfect: 4 fields in line 1: Item Number Available Inventory Retail Price Each Price 4 fields in line 2: 03657 456 12.95 2.77 4 fields in line 3: 101 778 23.95 3.28 Thanks a million for the kick in the right direction.
  5. I'm having trouble using my csv file to update my inventory. Here's how I get the CSV from a remote server: copy('http://www.mysupplie...0012538&fmt=csv' 'GeneratedList.csv'); Here's how the CSV looks when I open it in Notepad++. "Item Number","Available Inventory","Retail Price","Each Price" "03657","456","12.95","2.77" "101","779","23.95","3.28" "10212","42","144.00","48.00" "103","783","26.95","3.65" "10312","19","180.00","63.16" "105","1182","23.95","2.90" "107","171","25.95","3.70" "118","2888","25.95","3.69" "119","166","24.95","3.48" "12512","25","240.00","84.20" "12612","17","216.00","75.80" "127","0","24.95","3.24" "128","8614","23.95","3.35" "129","5366","23.95","3.28" "130","844","30.95","5.48" "131","40","19.95","2.90" "132","1985","23.95","3.27" "133","0","19.95","2.86" "134","2","24.95","3.60" "135","372","23.95","3.99" "136","1420","25.95","3.79" "137","3294","24.95","3.47" etc..... I've steped back to just try to parse and print it to the screen to see what happens with this code: $row = 1; if (($handle = fopen("GeneratedList.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); echo "<p> $num fields in line $row: <br /></p>\n"; $row++; for ($c=0; $c < $num; $c++) { echo $data[$c] . "<br />\n"; } } fclose($handle); } and I get this output: 105 fields in line 1: Item Number Available Inventory Retail Price Each Price "03657" 456 12.95 2.77 "101" 779 23.95 3.28 "10212" 42 144.00 48.00 "103" 783 26.95 3.65 "10312" 19 180.00 63.16 "105" 1182 23.95 2.90 "107" 171 25.95 3.70 "118" 2878 25.95 3.69 "119" 166 24.95 3.48 "12512" 25 240.00 84.20 "12612" 17 216.00 75.80 "127" 0 24.95 3.24 "128" 8614 23.95 3.35 "129" 5366 23.95 3.28 "130" 844 30.95 5.48 "131" 40 19.95 2.90 "132" 1985 23.95 3.27 "133" 0 19.95 2.86 "134" 2 24.95 3.60 "135" 372 23.95 3.99 "136" 1420 25.95 3.79 "137" 3294 24.95 3.47 "138" 0 28.95 4.86 "141" 41 22.95 3.90 "142" 1187 24.95 3.40 "142707" 10 269.95 59.99 "142708" 13 493.95 109.76 "142711" 1 674.95 150.00 "142718" 3 787.95 175.00 "142725" 3 265.95 59.00 "143" 383 26.95 3.69 "144" 416 22.95 3.99 "145" 295 26.95 3.84 "146" 1475 6962 fields in line 2: 25.95 3.80 "148" 1232 22.95 3.89 "150" It looks like somewhere along the line it's not recognizing the end of each line. It opens as expected in Calc and gives me 4 fields per line. If I manually nuke the header and upload it then it works fine. This is where I get confused. Any ideas or inspiration much appreciated. Ron
  6. Worked perfectly: $handle = fopen("GeneratedList.csv", "r+"); $header = 'true'; while (($data = fgetcsv($handle, 100000, ",")) !== FALSE) { if ($header = 'true') { $header = 'false'; break; } $num = count($data); for ($c=0; $c < $num; $c++) { Thanks a million.
  7. That works perfectly. Thanks! The problem I'm running into now is that the first row is the column names which need to be skipped. What would I add to this code to get that to happen? $handle = fopen("GeneratedList.csv", "r+"); while (($data = fgetcsv($handle, 100000, ",")) !== FALSE) { $num = count($data); for ($c=0; $c < $num; $c++) { if ($c = 1) { $supplier_reference = $data[($c-1)]; } if ($c = 2) { $quantity = $data[($c-1)]; mysql_query("UPDATE stock_available, product SET stock_available.quantity = $quantity WHERE stock_available.id_product = product.id_product AND product.supplier_reference = '$supplier_reference'") or die(mysql_error()); mysql_query("UPDATE stock_available, product_attribute SET stock_available.quantity = $quantity WHERE stock_available.id_product_attribute = product_attribute.id_product_attribute AND product_attribute.supplier_reference = '$supplier_reference'") or die(mysql_error()); } if ($c = 3) { } if ($c = 4) { } } } fclose($handle); Thanks again. Ron
  8. This one has me stumped. I need to copy a file from another server (one of my suppliers) to mine. Problem is the URL lloks like this: http://www.mysupplier.com/utilities/cgen.lasso?an8=10012538&fmt=csv which creates a file called GeneratedList.csv. I'd rather not bother reading it into a table and then parsing and saving it. Just a direct copy would be ideal. The rest of the script knows what to do with it once it's there. Any and all help appreciated. Cheers, Ron
  9. To add to this when I change it to $result = mysqli_query It works without error but the csv file is corrupted and won't open in excel or calc.
  10. YOU ROCK! mysql_fetch_row() works perfectly. Sorry to be so naive but how would I do that based on the code above? Thanks again.
  11. Hi all, Here's the code: $result = mysql_query("SELECT product_supplier.product_supplier_reference , product.price , product.wholesale_price FROM product_attribute INNER JOIN product ON product.id_product = product_attribute.id_product AND product.active = '1' INNER JOIN product_supplier ON product_supplier.id_product = product_attribute.id_product UNION SELECT product_supplier.product_supplier_reference , product.price , product.wholesale_price FROM product_supplier INNER JOIN product ON product.id_product = product_supplier.id_product AND product.active = '1' AND product.cache_default_attribute = '0'"); $fetch = array(); while($row = mysql_fetch_array($result)){ $fetch[] = $row; } $list = $fetch; $fp = fopen('product_export.csv', 'w'); foreach ($list as $fields) { fputcsv($fp, $fields); } fclose($fp); The SELECT works perfectly. It creates 3 columns. The code is supposed to save it as a csv with those 3 columns. Problem is it saves 6 columns (each one duplicated). I'm sure it's something silly and I just can't see it cause I've been staring at it too long. TIA Ron
  12. Hello, I'm working with the 1.5.1 version of PrestShop in case anyone is familiar with it. I've included my original message in the Presta forums below. Any ideas on where I'm going wrong? Any and all help would be much appreciated.
×
×
  • 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.