我有以下函数,目前位于 default.php 文件中,稍后我将移至 helper.php
function getauthor($shouts, $i){
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*')
->from('#__users')
->where('name = '. $shouts[$i]->name);
$db->setQuery($query);
$rows = $db->loadObjectList();
$i=0;
foreach ($rows as $row){
$author[$i]->id = $row->id;
$author[$i]->name = $row->name;
$i++;
}
return $author;
}
基本上我想做的是 print $author[$i]->name
,但每次我尝试使用以下代码执行此操作时:
print stripslashes($author[$i]->name);
我收到以下错误:
Undefined variable: author in C:\wamp\www\Joomla25\modules\mod_xxx\tmpl\default.php on line 98
Trying to get property of non-object in C:\wamp\www\Joomla25\modules\mod_xxx\tmpl\default.php on line 98
Cannot redeclare getauthor() (previously declared in C:\wamp\www\Joomla25\modules\mod_xxx\tmpl\default.php:60) in C:\wamp\www\Joomla25\modules\mod_xxx\tmpl\default.php on line 60
谁能告诉我哪里出错以及如何打印$author[$i]->name
?