Accessin array outside function?

I have a fuction that pulls an array from a mySQL database for Joomla!

But, how do i access that array outside my fucntion? My code doesnt work, as $rows is "NULL" when i try to act on it outside the function.
<?
defined('_VALID_MOS') or die('Direct access to this location not allowed');
 
getSessions();
//var_dump($rows);
foreach ( $rows as $row) {
	echo "$row->title $row->session_up\n";
}
 
function getSessions(){
	global $database;
	$sql= "select * from #__events_sessions where title like 'Stamps%' and session_down > now() order by session_up limit 1";
	$database->setQuery($sql);
	$rows = $database->loadObjectList();
	var_dump($rows);
//	foreach ( $rows as $row ) {
//		echo "$row->title $row->session_up\n";
//	}
	return $rows;
}
 
?>

Open in new window

LVL 12
j2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

j2Author Commented:
Added missing row in code snippet.
0
dr_dedoCommented:
provided that $database->loadObjectList(); does return an array, try this
<?
defined('_VALID_MOS') or die('Direct access to this location not allowed');
 
$rows = getSessions();
//var_dump($rows);
foreach ( $rows as $row) {
        echo "$row->title $row->session_up\n";
}
 
function getSessions(){
        global $database;
        $sql= "select * from #__events_sessions where title like 'Stamps%' and session_down > now() order by session_up limit 1";
        $database->setQuery($sql);
        $rows = $database->loadObjectList();
        var_dump($rows);
//      foreach ( $rows as $row ) {
//              echo "$row->title $row->session_up\n";
//      }
        return $rows;
}
 
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
j2Author Commented:
*groooooaaaaaaaaaan*

I CAN NOT beleive i did that....

I was sure my problem was that i screwed up in calling a class from Joomla! incorrectly.

I am so embarrased.
0
j2Author Commented:
Thanks heaps!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.