0

我的查询是:

$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 >  '0')";
$orderitemsattributes_result = mysql_query($orderitemsattributes_query);
while($row = mysql_fetch_array($orderitemsattributes_result)) {

echo $row['products_options_values'];
}

给了我以下内容:

 6 period day (TP6)NavyGold (j)Gold Lamé (17)LJD1 at back (free)

我希望能够将其转换为单个字符串以插入到数据库的另一个字段中。

我试过:

$tradebox_attributes_list = implode (',', $row);`

但我要么一无所获,要么得到存储在 $tradebox_attributes_list 中的不完整结果,具体取决于我放置内爆的位置。

我需要能够在代码中进一步读取这个变量,在结束 } 之后。

表结构为:

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', ''),

我需要能够获取存储在 products_options_values 字段中的所有结果(注意,这个订单只有六个)并将它们作为逗号分隔的列表存储在 tradebox_attributes_list 字段中。

根据刚刚更改的要求进行编辑:

我现在要扔扳手了。group_concat() 将起作用,但我刚刚被要求在单独的行上显示其中一个属性。例如,我们想要以下内容:6 Period Day, Navy, 1 at back (free) NEW LINE LJD £3.30

现在不是那么简单,因为我需要选择特定的 products_options_values,然后在单独的行上,选择不同的选项,它与 options_values_price 字段中的相关价格。

4

1 回答 1

0

您可以使用 agroup_concat()来获取值 group by order id。希望我们能看到桌子虽然..

SELECT group_concat(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 >  '0')
group by oa.orders_id;
于 2013-01-07T14:53:15.440 回答