Skip to content
Advertisement

Totaling the values of columns and get the average to save it on another table

I have a table work in a database that have columns score_1, score_2, score_3, and score_4. I want to get the total value and save it to database as a total_score. And from that total_score I want to get the average matching the work data with the vendor ID. How to achieve this? At the moment I have, the total_score as a raw view (not saved to the database). Here is the code for the table:

JavaScript

Here is the form where the user input the data

JavaScript

model

JavaScript

AdminController

JavaScript

Database https://imgur.com/a/N6NlcwJ Work Table

Vendor Table

Here is what I want to achieve https://imgur.com/a/fk4Yq92 What I want to achieve

Advertisement

Answer

For total score add this code in update_nilaipekerjaan() function befor save function :

JavaScript

and if you want to get the average add this codde :

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement