CSV Import Help

Hi wondered if someone could help me i have a csv import script and i need it to skip the cells which are EMPTY for additional images which is product_image and only insert the data which is in the cells for product_image

here is the code i have:

[php]if (isset($data[‘product_image’])) {
foreach ($data[‘product_image’] as $image) {

		$image = $image.".jpg";
		$image = str_replace (" ", "", $image);
		$filename = '/home/purchase/public_html/fancydresscostumesonline.co.uk/image/'. $image;

		if (file_exists($filename)) {
		$this->db->query("INSERT INTO " . DB_PREFIX . "product_image SET product_id = '" . (int)$product_id . "', image = '" . $this->db->escape($image) . "'");	
		} else {
			$this->db->query("INSERT INTO " . DB_PREFIX . "product_image SET product_id = '" . (int)$product_id . "', image = 'no_image.jpg'");

this code at moment addds a .jpg at the end of the numbers which are in the additional images column in the csv and the else statement no_image.jpg adds a no_image for all the empty CELLS for product_image so i need it customised so it skips the empty rows/cells and just cant think what to do:

This is code i though would work:

[php]foreach($file as $row){


$image = 'default.jpg';    

if( ! empty($row['product_image'])){    
	$image = trim($row['product_image']) . '.jpg';  

$image = '/home/purchase/public_html/fancydresscostumesonline.co.uk/image/' . $image ;    

if( ! file_exists($image)){    

	"INSERT INTO %s SET product_id = %d, image = '%s';",    
	DB_PREFIX . 'product_image',    

} [/php]

but i not sure if it will as not sure what goes before the foreach :frowning: hope someone can help i am a beginner at this.


Sponsor our Newsletter | Privacy Policy | Terms of Service