下面的代码使用 2 个表“category_path”和“category_description”来获取所有类别和子类别的 id=>name。我不擅长 mySql,所以如果你能帮助我,我将不胜感激。在此函数中,我还需要从名为“category”的其他(第三个)表中获取“cat_name”列的值https://i.stack.imgur.com/1PC4A.jpgpublic function getCategories($data = array()) { $sql = "SELECT cp.category_id AS category_id, GROUP_CONCAT(cd1.name ORDER BY cp.level SEPARATOR ' > ') AS name, c1.parent_id, c1.sort_order FROM " . DB_PREFIX . "category_path cp LEFT JOIN " . DB_PREFIX . "category c1 ON (cp.category_id = c1.category_id) LEFT JOIN " . DB_PREFIX . "category c2 ON (cp.path_id = c2.category_id) LEFT JOIN " . DB_PREFIX . "category_description cd1 ON (cp.path_id = cd1.category_id) LEFT JOIN " . DB_PREFIX . "category_description cd2 ON (cp.category_id = cd2.category_id) WHERE cd1.language_id = '" . (int)$this->config->get('config_language_id') . "' AND cd2.language_id = '" . (int)$this->config->get('config_language_id') . "'";
1 回答
精慕HU
TA贡献1845条经验 获得超8个赞
您已经category在第一个连接中使用该表,并且给它起了一个别名c1so
SELECT cp.category_id AS category_id, c1.cat_name,
. . .
. . .
- 1 回答
- 0 关注
- 66 浏览
添加回答
举报
0/150
提交
取消