Keyword

Get Username From User ID

More
6 years 9 months ago #165998 by Leon
Get Username From User ID was created by Leon
Hello!

I'm currently using RSForms Pro, and I desperately need some help with this issue in the title. I think I'm on the right track, but only need a tweek to get this done.

I currently have this code that is appropriately getting the user id from the author of the K2 item on page:
$db = JFactory::getDBO();
$articleid = JRequest::getInt('id');
$db->setQuery('SELECT created_by FROM #__k2_items WHERE id='.$articleid);
$myid=$db->loadResult();
return $db->loadResult();

Is there a way to make this code return the user's username instead of the user's ID?

Please Log in or Create an account to join the conversation.

More
6 years 9 months ago #166004 by Leon
Replied by Leon on topic Get Username From User ID
Nevermind! Got it!

Here it is if anyone is interested:
$db = JFactory::getDBO();
$articleid = JRequest::getInt('id');
$db->setQuery('SELECT created_by FROM #__k2_items WHERE id='.$articleid);
$myid=$db->loadResult();

$user = JFactory::getUser($myid);

return $user->username;

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
6 years 8 months ago #166049 by Krikor Boghossian
Replied by Krikor Boghossian on topic Get Username From User ID
Sorry for the late reply Leon.
Kudos :)

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum