Sum All Field Values from Particular Student

Sum All Field Values from Particular Student

by Alex N -
Number of replies: 2
Let's say there is a database with separate participants (approval required but approval button removed) with unlimited entries allowed.


If I have a field called [ [ Num1 ] ], how can I have the total value of all [ [ Num1 ] ] fields for a particular student display somewhere on the header of the List View.

See example below.


The total value of your Numbers is: 15

Name Numbers
Student A 5
Student A 7
Student A 3

Average of ratings: -
In reply to Alex N

Re: Sum All Field Values from Particular Student

by Matthias Giger -
Picture of Particularly helpful Moodlers

I had a smiliar problem and used a JavaScript hack to solve it but maybe there is a better solution:

<script>document.write("",Num1+Num2+Num3,"")</script>

This will add up all the values in the fields Num1-3 and display the sum of those numbers.

Average of ratings: Useful (2)
In reply to Matthias Giger

Re: Sum All Field Values from Particular Student

by Alex N -

I couldn't find any other way so I did end up doing it in JavaScript. Thanks Matthias.


<script type="text/javascript">

function calc1() {

    var table = document.getElementById("DBTable")

    var l=table.rows.length;

    var i;

    var Num1=0;

    for (i=1;i<l;i++) {

        Num1+= Number(parseInt(table.rows[i].cells[5].innerHTML,10));

    }

    document.getElementById("calcNum").innerHTML = Num1;

}

calc1()

</script>

Average of ratings: Useful (2)