how to get category name from category id?

2019-05-14 02:10发布

I am new in joomla.In my module i have to give select category option. I tried to get category name from back-end by following code but it doesn't work.Code..

$backId=$params->get('mycategory');
$db->setQuery('SELECT cat.title FROM #__categories cat RIGHT JOIN #__content cont ON cat.id = cont.catid WHERE cont.id='.$backId);
$category_title = $db->loadResult();

if ($category_title)
{
    echo $category_title;
}

how can i get the category name that i selected.Thanks...

1条回答
We Are One
2楼-- · 2019-05-14 03:03

Hope this may be work..

$db = JFactory::getDbo();
$id = jrequest::getint('id');
//match id to cat.id from _categories set to variable $id
$db->setQuery("SELECT cat.title FROM #__categories cat WHERE cat.id='$id'");
$category_title = $db->loadResult();
echo "$id";
echo "$category_title";
查看更多
登录 后发表回答