hook for calculating sum

juergen_mueller

DaDaBIK Guru
Hi,

I tried to show the sum of a column in a result grid but my function fails:

$hooks['MYTABLE']['resultsgrid_header']['before'] = 'dadabik_sum';

function dadabik_sum($id_user)
{
global $conn;

$result= "SELECT SUM(total) AS totalsum FROM MYTABLE where id_user = :id_user";

$row = mysql_fetch_assoc($result);

$sum = $row['totalsum'];

echo $sum;
}

Thanks for any hint,

Juergen
 

eugenio

Administrator
Staff member
Hello,
the resultsgrid_header hook is just a layout hook, it doesn't receive anything in input (no $id_user); if you want to use the current user as a parameter, you can use the global $current_user.
They query is also not correct (you miss the prepare and the bind steps).

Best,
 

juergen_mueller

DaDaBIK Guru
Hi, Eugenio

I modified the function and it's working now like I wanted: the total sum of a column will be calculated depending on the logged in user and shown in the results_grid header.

Best,

Juergen
 
Top