php - 如何通过数据库中的 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
...
期待结果
解决方案
你可以使用这个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
推荐阅读
- java - 从子类初始化私有变量
- r - 使用 distinct 和 ifelse dplyr 进行变异
- android - MaterialCardView 的不同角半径值
- python - 我们如何使用 python 在给定文本中实现共指解析?
- android - 获取当前片段变量值
- css - 为什么手机或平板电脑上的字体看起来比相应的浏览器尺寸小?
- android - 为什么我们需要提供 Repository 单例,因为注入的参数已经是单例了?
- java - Spring Data Mongodb 使用对象类型来收集
- c++ - 使用多个指向它的指针来管理一个对象
- php - Octobercms - 禁用缓存