如何从 opencart3 管理面板中的 MySQL 查询获取另一列值?

下面的代码使用 2 个表“category_path”和“category_description”来获取所有类别和子类别的 id=>name。我不擅长 mySql,所以如果你能帮助我,我将不胜感激。在此函数中,我还需要从名为“category”的其他(第三个)表中获取“cat_name”列的值

https://i.stack.imgur.com/1PC4A.jpg

public 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') . "'";



梦里花落0921
浏览 67回答 1
1回答

精慕HU

您已经category在第一个连接中使用该表,并且给它起了一个别名c1soSELECT cp.category_id AS category_id, c1.cat_name,. . .. . .
打开App,查看更多内容
随时随地看视频慕课网APP