0

My Situation

Im very new to Joomla and I installed a component called EasyBlog. What Im trying to do is get category_id from jos_easyblog_post table for a particular post_id and and echo it on the template. Im also not quite sure if its ok to put database connection script on the template itself?

jos_easyblog_post has few columns,

id - Post Id
category_id - Category that post belongs to
Hits etc etc.

Lets say id which is Post ID is 5 and how can I conenct to the database and go to jos_easyblog_post and look for the post id 5 and get the category_id associated with it? Thanks guys.

nasty
  • 6,797
  • 9
  • 37
  • 52

1 Answers1

3

The joys of using a CMS such as Joomla, is that scripts become easy. Connecting to the database is done using the code below:

$db = JFactory::getDbo();

To get results from a database table using Joomla 2.5 standards, you can try something like this:

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('category_id')
 ->from('#__easyblog_post')
 ->where('post_id = 5');
$db->setQuery($query);
$row = $db->loadResult();

echo $row;

Note that when defining a Joomla database table, the prefix is defined as #__

Lodder
  • 19,758
  • 10
  • 59
  • 100
  • Hi Lodder. Thanks. There was a `;` missing at the end of `$query` i guess. Also the output says just `Array`. Why is that? – nasty Dec 02 '12 at 23:54
  • @nasty - ah sorry, my mistake. I have updated my answer with the additional `;` and changed `loadObjectList` to `loadResult`. This will definitely work – Lodder Dec 03 '12 at 00:18