首页 > 解决方案 > 如何通过数据库中的 PHP 获取其中的完整 url 类别和产品列表?

问题描述

我想通过 Php 从数据库中获取 Opencart 3.0.3.2 中完整 url 产品的列表:

例子:

http://example.com/index.php?route=product/product&path=20_27&product_id=39
http://example.com/index.php?route=product/product&path=25_28&product_id=40
http://example.com/index.php?route=product/product&path=25&product_id=41
http://example.com/index.php?route=product/product&path=24_28&product_id=42
...

等等。

当然,如果您告诉我如何获取它并以 .xlsx 格式保存,那就太好了。让所有产品按顺序排列,即使没有数字顺序。只是链接!

在数据库中,我有:“products_in_category”表,其中有两列:

Product_id  Category_id
28           20
28           24
29           20
29           24
30           25
30           24
32           26

.... and so on

如您所见,由于此产品链接在“父类别”和“子类别”上,因此重复了相同的产品

但我需要完整的产品路径而不重复!

预期结果 -> 文件 .xlsx(Excel) *会很棒!或者只是 .txt 文件:

http://example.com/index.php?route=product/product&path=20_27&product_id=39
http://example.com/index.php?route=product/product&path=25_28&product_id=40
http://example.com/index.php?route=product/product&path=25&product_id=41
http://example.com/index.php?route=product/product&path=24_28&product_id=42
...

期待结果

在此处输入图像描述

标签: phpopencart

解决方案


你可以使用这个sql语句

SELECT CONCAT("http://example.com/index.php?route=product/product&path=", GROUP_CONCAT(category_id SEPARATOR '_'), "&product_id=", product_id) AS 'Product_links' FROM `oc_product_to_category` GROUP BY product_id

推荐阅读