Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7403387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:04:10+00:00 2026-05-29T05:04:10+00:00

I have a export script that export items to a csv file. I want

  • 0

I have a export script that export items to a csv file. I want to export the additional images for each item on each product row in the csv file.
That part looks like this:

$img_query=tep_db_query("SELECT additional_images_id, products_id, popup_images
                                      FROM " . TABLE_ADDITIONAL_IMAGES . " 
                                      WHERE products_id=" . $products['products_id'] ."");

if (!tep_db_num_rows($img_query)) {   
  $imageextra2 = " ";
   } else {
  $img_rows=tep_db_num_rows($img_query);
  while ($img = tep_db_fetch_array($img_query))     {  
            $img2 = $img['popup_images'];
            $pid = $img['products_id'];

                $a = array($img2);
                   foreach($a as &$img){ 

                  }
            foreach($a as $imageextra) {

            $imageextra = "http://www.URL.com/images/". $img2.";";
             $imageextra2 .= $imageextra;
            }
          }     }

But when I export more than one product that have additional images the images from the line abowe follows to the next line in the csv file.
Heres an exampe of the result. Each item has one additional image:

Item-A;AdditionalImage-A.jpg;AdditionalImage-A2.jpg
Item-B;AdditionalImage-A.jpg;AdditionalImage-A2.jpg;AdditionalImage-B.jpg;AdditionalImage-B2.jpg
Item-C;AdditionalImage-A.jpg;AdditionalImage-A2.jpg;AdditionalImage-B.jpg;AdditionalImage-B2.jpg;AdditionalImage-C.jpg;AdditionalImage-C2.jpg

What can I do to get this working?

Cheers,
Fredrik

Edit
Below is the complete section of php that grab the info and generate the export file:

<?php
  require('includes/application_top.php');

  if (isset($_POST['create'])) {
    if (isset($_POST['product']) && is_array($_POST['product'])) {

        foreach ($_POST['product'] as $product_id) {
            $products_query_raw = "select p.products_id, p.products_image, p.products_model, products_image_pop, p.products_price, p.products_quantity, p.products_tax_class_id, pd.products_name, pd.products_description from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = $product_id and pd.products_id = p.products_id and pd.language_id = $languages_id";
            $products_query = tep_db_query($products_query_raw);
            if ($products = tep_db_fetch_array($products_query)) {

//++++ QT Pro: End Changed Code
    $products_attributes_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . $products['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "'");
    $products_attributes = tep_db_fetch_array($products_attributes_query);
    if ($products_attributes['total'] > 0) {
//++++ QT Pro: Begin Changed code
      $products_id = $products['products_id']; 
      require_once(DIR_WS_CLASSES . 'pad_single_radioset_print.php'); 
      $class = 'pad_single_radioset';
      $pad = new $class($products_id);
      $attribs .= $pad->draw();
//++++ QT Pro: End Changed Code
    }

                $product_desc = (isset($_POST['strip_tags']) && ($_POST['strip_tags'] == '1'))
                                ? strip_tags($products['products_description'],'<br>, <li>, </li>, <ul>, </ul>')  //ORG
                                : $products['products_description'];

                $tax_rate = 0;
                $taxes_query_raw = "select tax_rate from " . TABLE_TAX_RATES . " where tax_class_id = " . $products['products_tax_class_id'];
                $taxes_query = tep_db_query($taxes_query_raw);
                while ($taxes = tep_db_fetch_array($taxes_query)) {
                    $tax_rate += $taxes['tax_rate'];
                }
                $tax = ($products['products_price'] * $tax_rate) / 100;
                $stock = $products['products_quantity'];

                $product_desc=preg_replace("/([[:space:]]{2,})/",' ',$product_desc);

// Categories - just show the sub-category      
                $categories_list = Array();
                $categories_query_raw = "select cd.categories_name, cd.categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " ptc, " . TABLE_CATEGORIES_DESCRIPTION . " cd where ptc.products_id = " . $products['products_id'] . " and cd.categories_id = ptc.categories_id and cd.language_id = $languages_id";
                $categories_query = tep_db_query($categories_query_raw);
                while ($categories = tep_db_fetch_array($categories_query)) {
                    $categories_list[] = $categories['categories_name'];
                    $categories_id = $categories['categories_id'];
                }
                $category_name = implode(' / ', $categories_list);

// Additional images    
      $img_query=tep_db_query("SELECT additional_images_id, products_id, popup_images
                                          FROM " . TABLE_ADDITIONAL_IMAGES . " 
                                          WHERE products_id=" . $products['products_id'] ."");

  if (!tep_db_num_rows($img_query)) {     
      $imageextra2 = "; ; ";

  } else {
      $img_rows=tep_db_num_rows($img_query);

      while ($img = tep_db_fetch_array($img_query))     {  
                $img2 = $img['popup_images'];
                $pid = $img['products_id'];

                $a = array($img2);

                $imageextra2 = " "; # This avoid letting the additional images from lines abowe follow.

                foreach($a as $imageextra) {
                $imageextra = "http://www.URL.com/images/". $img2.";";
                $imageextra2 .= $imageextra;
                }
               } 
}

                $export .= 
                           $products['products_model'].';'.
                           $products['products_name'].';'.
                           $product_price.';'.
                           $products['products_quantity'].';'.
                           $product_desc.';'.
                           $categories_id.';'.
                           $shipping_cost.';'.
                           'http://www.URL.com/images/'.basename($products['products_image_pop']).';'.
                           $imageextra2.
                            "\n";
            }
        }


        if ($fp = @fopen($_SERVER['DOCUMENT_ROOT'] . '/feed/t-butik.csv', 'w')) {
            $utf = iconv("windows-1252","ISO-8859-1",$export);
            $out = 'variable_name='.$utf;
            fwrite($fp, $utf);
            fclose($fp);
            $messageStack->add("Feed generates successfully!!!", 'success');
        } else {
            $messageStack->add("ERROR: Permissions error trying to write feed to disk.", 'error');
        }
    }
  }
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:04:11+00:00Added an answer on May 29, 2026 at 5:04 am

    There doesn’t seem to be enough of the code to give you an absolute answer but my guess would be that the variable $imageextra2 is not being reset on each iteration.

    When you change a product you should reset the variable thats holding the images, which I assume is $imageextra2

    Change This

    if (!tep_db_num_rows($img_query)) {     
      $imageextra2 = "; ; ";
    
    } else {
      $img_rows=tep_db_num_rows($img_query);
    
      while ($img = tep_db_fetch_array($img_query))     {  
                $img2 = $img['popup_images'];
                $pid = $img['products_id'];
    
                $a = array($img2);
    
                $imageextra2 = " "; # This avoid letting the additional images from lines abowe follow.
    
                foreach($a as $imageextra) {
                $imageextra = "http://www.URL.com/images/". $img2.";";
                $imageextra2 .= $imageextra;
                }
               } 
    }
    

    To This

    $imageextra2 = " "; # resets images
    
    if (tep_db_num_rows($img_query)) {     
        $img_rows=tep_db_num_rows($img_query);
    
        while ($img = tep_db_fetch_array($img_query))     {  
            $img2 = $img['popup_images'];
            $pid = $img['products_id'];
    
            $a = array($img2);                
    
            foreach($a as $imageextra) {
                $imageextra = "http://www.URL.com/images/". $img2.";";
                $imageextra2 .= $imageextra;
            }
        } 
    }
    

    Best Regards,

    Jason

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a requirement to export a dataset as a CSV file. I have
Ok, so I have the following script that will export data from my database
I have a script that exports an environment variable and starts some subscripts. export
I have a script that opens Powerpoint from my application and exports all slides.
I have to create a script that takes a mySQL table, and exports it
So I have an 'export' application that arrives the user at an end page
I have to do an export from DB to CSV. ( .NET 2 )
I have created an Item Template using the Export Template wizard. I opened up
I have a little JUnit-Test that export an Object to the FileSystem. In the
We have a service that runs methods used for data import/export at specified intervals.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.