Good morning everyone,
I would need to display not only the sum of the values in the column but also their average.
How can I do?
Can anyone help me with a sample code?
Can hooks be used so I don't have to manually edit the page each time?
Thanks again.
average values column
Re: average values column
Hi,
if you need average displayed, you will need to change the layout of the page.
You can do this either by using Javascript (someone else on the forum can probably help) and inject "something" (see below) at the position or change the base layout file of the page in the /templates/tablename-dv or just add the average to the footer function of your file.
Something like this should work:
Using the code above (not tested), you should be able to display your average by simply calling
from anywhere within your page code.
If this does not work, you may need to calculate the average directly in the _ini function and save the calculated result to a variable that you can reuse later (session var).
Olaf
if you need average displayed, you will need to change the layout of the page.
You can do this either by using Javascript (someone else on the forum can probably help) and inject "something" (see below) at the position or change the base layout file of the page in the /templates/tablename-dv or just add the average to the footer function of your file.
Something like this should work:
Code: Select all
function avgDisplay(&$options) {
$sql_from = $options->QueryFrom;
$sql_where = $options->QueryWhere;
$sql = "SELECT AVG(YOURFIELD) AS AverageFromYOURFIELD FROM (SELECT * FROM (" . $sql_from . ") WHERE (" . $sql_where ."));"
$avgCalculated = sqlValue($sql);
return $avgCalculated;
}
Using the code above (not tested), you should be able to display your average by simply calling
Code: Select all
echo avgDisplay($options);
If this does not work, you may need to calculate the average directly in the _ini function and save the calculated result to a variable that you can reuse later (session var).
Olaf
Some postings I was involved, you might find useful:
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button
Re: average values column
Thanks for the reply.
Do you know where the script that makes the Sum work is? Because I would like to place them close together
Do you know where the script that makes the Sum work is? Because I would like to place them close together
Re: average values column
Hi,
sorry, no, I not not know this.
Olaf
sorry, no, I not not know this.
Olaf
Some postings I was involved, you might find useful:
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button