Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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