how to get category name from category id?

2019-05-14 02:19发布

问题:

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:

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";