简体   繁体   English

基于外部表中的用户ID的joomla 2.5 echo用户名

[英]joomla 2.5 echo username based on userid from an external table

I've dug about a bit looking for an answer to this. 我挖了一点,寻找答案。 My lack of skill in php and sql are killing me. 我缺乏php和sql的技能正在杀死我。

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). 我有一个表,该表使用在此表中创建条目的任何给定用户的用户标识,我需要抓取它“ associated_user”(等于joomla“ userid”)并显示该用户标识的用户名(有意义的希望) 。

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" 但是随着“在非对象上调用成员函数setQuery()”而逐渐消失

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. 我已经看到了其他一些解决方案,这些解决方案假定我打算直接从用户表中拉出,但是我需要将其转换到某个地方,而且我真的很迷失,感谢您提供的所有协助。

Add below line in your code. 在代码中添加以下行。

 $db=JFactory::getDBO();

And use 并使用

$db->setQuery($associated_user); $ db-> setQuery($ associated_user);

inseted of 插入

$db->setQuery($user_type); $ 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"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM