batch import csv to drupal database


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /**
  2.  * function to batch update the sell_price for ubercart products from a csv file
  3.  * @param string path to csv file
  4.  */
  5. function sitehelper_batchupdate($csv_file) {
  6. $row = 1;
  7. if (($handle = fopen($csv_file, "r")) !== FALSE) {
  8. while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) {
  9. $num = count($data);
  10. //print $num;
  11. //print "<p> $num fields in line $row: <br /></p>\n";
  12. $row++;
  13.  
  14. //print $data[0] . " " . $data[1] . $data[2] . $data[3] . "<br />" ;
  15.  
  16. db_query('update uc_products set sell_price = "%s" where nid = %d and vid = %d', $data[0], $data[2], $data[3]);
  17.  
  18. }
  19. fclose($handle);
  20. }
  21. }
  22.  
  23. //sitehelper_batchupdate("http://[site_url]/sites/all/modules/sitehelper/books.csv");

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.