Note that there are some explanatory texts on larger screens.

plurals
  1. POforeach loop prevous data in export file
    primarykey
    data
    text
    <p>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:</p> <pre><code>$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 &amp;$img){ } foreach($a as $imageextra) { $imageextra = "http://www.URL.com/images/". $img2.";"; $imageextra2 .= $imageextra; } } } </code></pre> <p>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:</p> <pre><code>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 </code></pre> <p>What can I do to get this working?</p> <p>Cheers, Fredrik</p> <p><em>Edit</em> Below is the complete section of php that grab the info and generate the export file:</p> <pre><code>&lt;?php require('includes/application_top.php'); if (isset($_POST['create'])) { if (isset($_POST['product']) &amp;&amp; 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'] &gt; 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-&gt;draw(); //++++ QT Pro: End Changed Code } $product_desc = (isset($_POST['strip_tags']) &amp;&amp; ($_POST['strip_tags'] == '1')) ? strip_tags($products['products_description'],'&lt;br&gt;, &lt;li&gt;, &lt;/li&gt;, &lt;ul&gt;, &lt;/ul&gt;') //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-&gt;add("Feed generates successfully!!!", 'success'); } else { $messageStack-&gt;add("ERROR: Permissions error trying to write feed to disk.", 'error'); } } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload