douyi3760 2016-03-14 14:44
浏览 47
已采纳

在php中的单独列表上匹配值

Sorry if this is a little long winded but here's some background.

I'm migrating some products from one shopping cart to another. the original cart is very old and the export file only gives the option id for different product options. eg. if a product comes red, yellow and blue it might give me the option ids 1,2 and 3.

I have managed to get a separate list showing all available option ids and the option it refers to.

So, List A shows me each product and the option IDs available to it like so:

List A

In this example product_id 1 could be a T shirt, option_id 11 could be "colour" and the various option_value_ids could be red, blue, yellow etc

List B shows me what each option_value_id means in real terms like so:

List B

Basically I'd like to write a PHP script which will compare the two lists and for each unique product ID then for each unique option ID, output a line of text in the following format:

product_id;option_id; list of option values separated by commas eg

1;11;red,blue,green,yellow...

I'm fairly new to PHP and started by putting together a webform so I could paste in the data from the spreadsheet but I think I'm barking up the wrong tree. I then thought maybe comparing them as 2 MySQL tables in a database?

Could someone please point me in the right direction?

  • 写回答

1条回答 默认 最新

  • douji0073 2016-03-14 15:10
    关注
    SELECT a.product_id, a.option_id, GROUP_CONCAT(DISTINCT b.option_name SEPARATOR ', ') as option_names 
    FROM listA a 
    LEFT JOIN listB b ON a.option_value_id = b.option_id
    GROUP BY a.product_id, a.option_id;
    

    Should work - I'm writing it from memory :) If not - try to tune it up. You can export it then to CSV.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求指导ADS低噪放设计
  • ¥15 CARSIM前车变道设置
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存