我想获得子类别的所有父类别标题 所以在mysql中我可以使用此代码
执行此操作SELECT T2.id, T2.title
FROM (
SELECT
@r AS _id,
(SELECT @r := parent_id FROM `up8te_categories` WHERE id = _id) AS parent_id,
@l := @l + 1 AS lvl
FROM
(SELECT @r := 8, @l := 0) vars,
`up8te_categories` h
WHERE @r <> 0) T1
JOIN `up8te_categories` T2
ON T1._id = T2.id
ORDER BY T1.lvl DESC
但是在joomla中我们有API用于查询 我想知道如何在joomla中使用它?
我知道这样的事情:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName(array('title')))
->from(......??????......)
->join('INNER', $db->quoteName('#__categories', 'T2') . ' ON (T1._id = T2.id)')
->order('T1.lvl DESC');
$db->setQuery($query);
$rows = $db->loadObjectList();
但我不知道如何设置从我想再次选择..
我能做什么?
亲切的问候。答案 0 :(得分:0)
我更喜欢将$ query用作字符串,如下所示:
$db = JFactory::getDbo();
$query = 'SELECT T2.id, T2.title
FROM (
SELECT
@r AS _id,
(SELECT @r := parent_id FROM #__categories WHERE id = _id) AS parent_id,
@l := @l + 1 AS lvl
FROM
(SELECT @r := 8, @l := 0) vars,
#__categories h
WHERE @r <> 0) T1
JOIN #__categories T2
ON T1._id = T2.id
ORDER BY T1.lvl DESC';
$db->setQuery($query);