I wrote a simple php page integrated with joomla database. I wrote two functions and called them.
if the code within the functions is wrote as non-function (on the code itself) it works perfectly. BUT! when the code is in function and called from the page the entire screen turns white.
the code is simple... the first function get a user's id and return a sum of numbers in a table. the second function get a user's username and returns it id number. to make sure the functions work, I sent to them specific values (24 to the first function and 'admin' to the second one).
the code:
<?php
defined('_JEXEC') or die('Restricted access');
$items = $params->get('items', 10);
$db =& JFactory::getDBO();
function get_sum($uid)
{
$sum = 0;
$query = "SELECT orderpayment_amount
FROM #__j2store_orders
WHERE user_id = '$uid'
ORDER BY id DESC";
$db->setQuery( $query, 0 , $items );
$rows = $db->loadObjectList();
foreach($rows as $row)
{
$sum = $sum + $row->orderpayment_amount;
}
return "$sum";
}
function getTalId($u)
{
$query = "SELECT id
FROM #__users
WHERE username = '$u'
ORDER BY id DESC";
$db->setQuery( $query, 0 , $items );
$rows = $db->loadObjectList();
foreach($rows as $row)
{
return $row->id;
}
}
echo get_sum(42);
echo getTalId('admin');
?>
I'm stuck for two days with this problem. I'd appreciate any help. thanks a-head.