Jump to content

CSV insert


techker

Recommended Posts

hey guys i have an existing code that inserts from scv to 1 DB.

 

is there a way to add 2 more?

 

cause there is 3 db for the products

 

products(product title-ful and short description)

products_images(image file name)

products_attribute_values(quantity and price)

 

$csv->file_new_name_body = $filename;
			$csv->Process(_UPLOAD_DIR_);

			if (!$csv->processed) {
				$message .= 'CSV upload error: '.$csv->error;
			} else {
				$row = 0;

				if (($handle = fopen(_UPLOAD_DIR_.$csv->file_dst_name, "r")) !== false) {
					while (($data = fgetcsv($handle, 1000, ",", '"')) !== false) {
						$sql = "INSERT INTO ".$TABLES['PRODUCTS']."
							SET categories_id = ".intval($_REQUEST['categories_id']).",
								order_id = 0,
								status = ".intval($_REQUEST['status']).",
								featured = 0,
								product_title = '".trim(saveToDB($data[0]))."',
								short_description = '".trim(saveToDB($data[1]))."',
								full_description = '".trim(saveToDB($data[2]))."'";
						$sql_result = mysql_query($sql, $connection) or die ('Could not execute SQL query:<br />'.$sql.'<br /><strong>'.mysql_error().'</strong>');

Link to comment
https://forums.phpfreaks.com/topic/259619-csv-insert/
Share on other sites

It depends where in the array the short description is. If its in the first column then you want to put it in as $data[0]; second column is $data[1] and so on....

 

Also, if your trimming everything you put through the saveToDB() function you should include the trim in that function; else your re-writing code for no reason.

Link to comment
https://forums.phpfreaks.com/topic/259619-csv-insert/#findComment-1331159
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.