title: Converting results of a MySQL query into a string
body: <p>My query is:</p>
  
  <pre><code>$orderitemsattributes_query = "SELECT products_options_values
  FROM orders_products_attributes oa
  WHERE oa.orders_id
  IN (
  SELECT DISTINCT o.orders_id
  FROM orders o
  WHERE o.exported =  '0'
  AND o.orders_id &gt;  '0')";
  $orderitemsattributes_result = mysql_query($orderitemsattributes_query);
  while($row = mysql_fetch_array($orderitemsattributes_result)) {
  
  echo $row['products_options_values'];
  }
  </code></pre>
  
  <p>gives me the following:</p>
  
  <pre><code> 6 period day (TP6)NavyGold (j)Gold Lamé (17)LJD1 at back (free)
  </code></pre>
  
  <p>I want to be able to convert this to a single string for insertion into another field on the database.</p>
  
  <p>I tried:</p>
  
  <pre><code>$tradebox_attributes_list = implode (',', $row);`
  </code></pre>
  
  <p>but i either don't get anything, or i get incomplete results stored in $tradebox_attributes_list depending where i put the implode.</p>
  
  <p>I need to be able to read this variable some way further along the code, well after the closing }.</p>
  
  <p>Table Structure is:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `orders_products_attributes` (
    `orders_products_attributes_id` int(11) NOT NULL AUTO_INCREMENT,
    `orders_id` int(11) NOT NULL DEFAULT '0',
    `orders_products_id` int(11) NOT NULL DEFAULT '0',
    `products_options` varchar(32) NOT NULL DEFAULT '',
    `products_options_values` text NOT NULL,
    `options_values_price` decimal(15,4) NOT NULL DEFAULT '0.0000',
    `price_prefix` char(1) NOT NULL DEFAULT '',
    `product_attribute_is_free` tinyint(1) NOT NULL DEFAULT '0',
    `products_attributes_weight` float NOT NULL DEFAULT '0',
    `products_attributes_weight_prefix` char(1) NOT NULL DEFAULT '',
    `attributes_discounted` tinyint(1) NOT NULL DEFAULT '1',
    `attributes_price_base_included` tinyint(1) NOT NULL DEFAULT '1',
    `attributes_price_onetime` decimal(15,4) NOT NULL DEFAULT '0.0000',
    `attributes_price_factor` decimal(15,4) NOT NULL DEFAULT '0.0000',
    `attributes_price_factor_offset` decimal(15,4) NOT NULL DEFAULT '0.0000',
    `attributes_price_factor_onetime` decimal(15,4) NOT NULL DEFAULT '0.0000',
    `attributes_price_factor_onetime_offset` decimal(15,4) NOT NULL DEFAULT '0.0000',
    `attributes_qty_prices` text,
    `attributes_qty_prices_onetime` text,
    `attributes_price_words` decimal(15,4) NOT NULL DEFAULT '0.0000',
    `attributes_price_words_free` int(4) NOT NULL DEFAULT '0',
    `attributes_price_letters` decimal(15,4) NOT NULL DEFAULT '0.0000',
    `attributes_price_letters_free` int(4) NOT NULL DEFAULT '0',
    `products_options_id` int(11) NOT NULL DEFAULT '0',
    `products_options_values_id` int(11) NOT NULL DEFAULT '0',
    `products_prid` tinytext NOT NULL,
    `tradebox_attributes_list` text NOT NULL,
    PRIMARY KEY (`orders_products_attributes_id`),
    KEY `idx_orders_id_prod_id_zen` (`orders_id`,`orders_products_id`)
  ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=77065 ;
  
  Sample of one entry is:
  
  
  (76569, 22959, 34813, 'Lesson format', '6 period day (TP6)', 0.0000, '+', 1, 0, '+', 1, 1, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, '', '', 0.0000, 0, 0.0000, 0, 5, 55, '30:499bc45895cd0baaef055a57cb36df5d', ''),
  (76570, 22959, 34813, 'Cover', 'Navy', 0.0000, '+', 1, 0, '+', 1, 1, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, '', '', 0.0000, 0, 0.0000, 0, 1, 2, '30:499bc45895cd0baaef055a57cb36df5d', '1 at back (free)'),
  (76571, 22959, 34813, 'Wire', 'Gold (j)', 0.0000, '', 1, 0, '', 1, 1, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, '', '', 0.0000, 0, 0.0000, 0, 4, 49, '30:499bc45895cd0baaef055a57cb36df5d', ''),
  (76572, 22959, 34813, 'Ribbon', 'Gold Lamé (17)', 0.0000, '+', 1, 0, '+', 1, 1, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, '', '', 0.0000, 0, 0.0000, 0, 3, 29, '30:499bc45895cd0baaef055a57cb36df5d', ''),
  (76573, 22959, 34813, 'Initials (Max 4)', 'LJD', 3.3000, '+', 1, 0, '+', 1, 1, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, '', '', 0.0000, 0, 0.0000, 0, 2, 0, '30:499bc45895cd0baaef055a57cb36df5d', ''),
  (76574, 22959, 34813, 'Plastic pockets', '1 at back (free)', 0.0000, '+', 1, 0, '+', 1, 1, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, '', '', 0.0000, 0, 0.0000, 0, 6, 84, '30:499bc45895cd0baaef055a57cb36df5d', ''),
  </code></pre>
  
  <p>I need to be able to take all the results stored in the products_options_values field (note, there are six just for this order) and store them as a comma separated list in the tradebox_attributes_list field.</p>
  
  <p>EDITED AS REQUIREMENTS JUST BEEN CHANGED:</p>
  
  <p>I'm about to throw a spanner in the works now. group_concat() will work, but i have just been asked to display one of the attributes on a separate line. For instance, we want the following:
    6 Period Day, Navy, 1 at back (free) <em>NEW LINE</em>
    LJD  £3.30</p>
  
  <p>Not so simple now as i need to select specific products_options_values, then on a separate line, select a different option and it's associated price from the options_values_price field. </p>