Function which returns an array appears to return empty..?
Posted: Wed Aug 18, 2010 9:57 pm
Hey guys!
I just typed this code up from scratch and, as I am not perfect with php syntax yet, I KNEW I was going to have some errors.. Can you tell me if anything is wrong with this??
First of all, I am working with Joomla 1.5 and I have created a new module.
"helper.php" contains the following class and function:
Then, in my "mod_mynewmodule.php", I include the "helper.php" file and call the function, assigning it to a variable:
Now, for the part I wasn't completely syntax-confident about, I echo the variable contents onto my page:
Is there anything that stands out as being a problem?? I have checked the php manual for all of my code and I am pretty sure this is the proper way to do this. However, my echo statement echos nothing...
I just typed this code up from scratch and, as I am not perfect with php syntax yet, I KNEW I was going to have some errors.. Can you tell me if anything is wrong with this??
First of all, I am working with Joomla 1.5 and I have created a new module.
"helper.php" contains the following class and function:
Code: Select all
class modComHelper
{
function getComData($params, $user)
{
$db =& JFactory::getDBO();
$userid = $user->get('id');
$query = "SELECT * FROM `ext_usertable` WHERE `refid` = '".$userid."'";
$db->setQuery($query);
$data['totalref'] = mysql_num_rows($db->query()); // This line counts the number of rows that contain instructors id as refid
$query = "SELECT `totalmade` FROM `ext_usertable` WHERE `id` = '".$userid."'";
$db->setQuery($query);
$totalmade = mysql_fetch_array($db->query());
$data['totalmade'] = $totalmade['totalmade'];
$query = "SELECT `totalcol` FROM `ext_usertable` WHERE `id` = '".$userid."'";
$db->setQuery($query);
$totalcol = mysql_fetch_array($db->query());
$data['totalcol'] = $totalcol['totalcol'];
$query = "SELECT `ppemail` FROM `ext_usertable` WHERE `id` = '".$userid."'";
$db->setQuery($query);
$ppemail = mysql_fetch_array($db->query());
$data['ppemail'] = $ppemail['ppemail'];
$query = "SELECT `accountbal` FROM `ext_usertable` WHERE `id` = '".$userid."'";
$db->setQuery($query);
$accountbal = mysql_fetch_array($db->query());
$data['accountbal'] = $accountbal['accountbal'];
return $data;
}
}
Code: Select all
require_once( dirname(__FILE__).DS.'helper.php' );
require( JModuleHelper::getLayoutPath( 'mod_mynewmodule' ) );
$user =& JFactory::getUser();
$comdata = modComHelper::getComData($params, $user);
Code: Select all
<?php echo $comdata['totalref']; ?>
Is there anything that stands out as being a problem?? I have checked the php manual for all of my code and I am pretty sure this is the proper way to do this. However, my echo statement echos nothing...