Pergunta

I've dug about a bit looking for an answer to this. My lack of skill in php and sql are killing me.

I have a table that utilizes the userid of any given user that creates an entry in this table and I need to grab it "associated_user" (equals a joomla "userid") and display instead the username of that userid (hope that makes sense).

I can display the associated user like this just fine

<?php echo $row->associated_user; ?>

I thought this would echo the result I needed

<?php 
$associated_user = "SELECT * FROM #__users  WHERE id='".$row->userid."' ";
$db->setQuery($user_type);
$user_type_detail = $db->loadAssoc();
echo $user_type_detail["username"];
?>

but its eroring with "Call to a member function setQuery() on a non-object"

I've seen some other solutions that assume I intend to pull directly from the user table, but I need to convert it somewhere and im really lost, thanks for any and all assistance.

Foi útil?

Solução

Add below line in your code.

 $db=JFactory::getDBO();

And use

$db->setQuery($associated_user);

inseted of

$db->setQuery($user_type);

Try it

$db=JFactory::getDBO();

$associated_user = "SELECT * FROM #__users  WHERE id='".$row->userid."' ";
$db->setQuery($associated_user);
$user_type_detail = $db->loadAssoc();
echo $user_type_detail["username"];
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top