Return to Snippet

Revision: 20896
at November 30, 2009 09:48 by ReeceMarsland


Initial Code
/**
 * function to batch update the sell_price for ubercart products from a csv file
 * @param string path to csv file
 */
function sitehelper_batchupdate($csv_file) {
	$row = 1;
	if (($handle = fopen($csv_file, "r")) !== FALSE) {
	    while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) {
	        $num = count($data);
	        //print $num;
	        //print "<p> $num fields in line $row: <br /></p>\n";
	        $row++;
	
	        //print $data[0] . " " . $data[1] . $data[2] . $data[3] . "<br />" ;
	        
	        db_query('update uc_products set sell_price = "%s" where nid = %d and vid = %d', $data[0], $data[2], $data[3]);
	       
	    }
	    fclose($handle);
	}
}

//sitehelper_batchupdate("http://[site_url]/sites/all/modules/sitehelper/books.csv");

Initial URL

                                

Initial Description

                                

Initial Title
batch import csv to drupal database

Initial Tags
csv, drupal, update

Initial Language
PHP