I have the following function, which at the moment is in the default.php file, which I will later on move to the 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;
}
Basically what I want to do is, print $author[$i]->name, but every time I try and do this using the following code:
print stripslashes($author[$i]->name);
I get the following errors:
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
Can anyone show me where I am going wrong and how to print $author[$i]->name?
You need to have the variable
authordefined in the place where you call:In the smallest possible example: