1

I am trying to show all subscribed Kunena threads based on the current logged in user.

Kunena stores the subscribed threads in the '#__kunena_user_topics' table, I've written the following but it's not working:

$user = JFactory::getUser();
$query="SELECT `topic_id` FROM `b2ygx_kunena_user_topics` WHERE `user_id` = ' . $user->id . '"
echo $query;

1 Answer 1

2

I would suggest you stick to proper Joomla coding standards for your database query. You can always refer to the Joomla documentation to double check if you've done something properly or not.

Have a try of the following:

$db   = JFactory::getDbo();   // Initiate database connection
$user = JFactory::getUser();  // Get user object

$query = $db->getQuery(true);     
$query->select($db->quoteName('topic_id'))
      ->from($db->quoteName('#__kunena_user_topics'))
      ->where($db->quoteName('user_id') . ' = '. $db->quote($user->id));
$db->setQuery($query);

$results = $db->loadObjectList();

Now that you have an object of results, you can perform a loop and echo the results, like so:

foreach ($results as $result)
{
    echo $result->topic_id . '<br>';
}

This will output something like the following:

26
12
5
89

Hope this helps

5
  • Thanks. I've tried this but am getting an error 'Fatal Error: Object of class stdClass could not be converted to string in modules/mod_my_active_kunena_threads/tmpl/default.php on line 18' The line is "echo $result . '<br>';" Apr 14, 2015 at 15:23
  • @RustyJoomla - Ahh ok...am I right in assuming you're using Joomla 3.4?
    – Lodder
    Apr 14, 2015 at 15:36
  • Yes, Joomla 3.4.1 Apr 14, 2015 at 15:37
  • I'm getting the same error. This wasn't an issue in 3.3.6 but they must have changed something in 3.4....I'll let you know once I've found the solution
    – Lodder
    Apr 14, 2015 at 15:40
  • @RustyJoomla - Figured it out. Change echo $result . '<br>'; to echo $result->topic_id . '<br>';
    – Lodder
    Apr 14, 2015 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.