問題描述
osCommerce mysql 導出到 Excel (osCommerce mysql export to Excel)
我需要將 osCommerce 產品數據庫導出到 Excel。目前有幾個表:
‑ Products (list with all the products)
‑ Options (labels of the different options, e.g. size, color, etc)
‑ Options_Products (list will all the options for a given product, organised by product_id, option_id and value (e.g. red, 32, etc.))
我必須在一行中導出每個產品,每個選項(例如顏色)有一列,所有值(逗號分隔)。如果某些選項不適用於某些產品,則該字段應為空或 null。
product_id
product_name
...
color (red, blue)
size (null)
some other option (23, 24, 24)
another option (null)
我很難創建這個 MySQL 查詢,我將不勝感激。
參考解法
方法 1:
I'm pretty sure you will not be able to do this by a single query or your query will have some sub‑queries.
I faced same problem and had to create a separate class. First it got an array (list) of products, and than, iterating products list, requested features list, including features names and values, for every product.
In some cases it's easier to make several methods in a class and get data "step‑by‑step" instead of trying to make a single complicated query.
Keep it simple, and good luck.
(by Boris、lazy.lizard)