Home > database >  how to sum column using javacript?
how to sum column using javacript?

Time:04-08

so, i'm trying to sum column from editable textbox(popover?)

table

pop up

what im trying to do is to sum Kehadiran tugas UTS Uas = total and if "Total" > 80 then Nilai = A

table is conected to mysql database

<?php

include('database_connection.php');

$column = array("Id_krs", "NIM_krs_Mhs","Nama" , "Kode_Matakuliah_krs", "Semester_Ambil", "Kehadiran","Tugas", "UTS", "UAS", "Total", "Nilai", "Mutu");

//$sum = array_sum(array_column($Kehadiran,$Tugas,$UTS,$UAS 'Total'));

since im very bad/beginer at php, try so many option, just can't get it to works. have no idea how to use the code.

any kind of help is highly appreciated. thank you.

CodePudding user response:

if you trying to sum specific columns in the array, let's suppose the columns array here represent the data in the same sequence

$column = array("Id_krs", "NIM_krs_Mhs","Nama" , "Kode_Matakuliah_krs", "Semester_Ambil", "Kehadiran","Tugas", "UTS", "UAS", "Total", "Nilai", "Mutu");

so to sum (Kehadiran tugas UTS Uas)

then it will become like this

$total = $column[5]   $column[6]   $column[7]   $column[8];

also, you can sum these numbers from the database add this to your select query

(Kehadiran   Tugas   UTS   UAS) AS total

CodePudding user response:

$total = array_sum([$Kehadiran, $tugas, $UTS, $Uas])

if ($total >  80) {
  $nilai = 'A'
}
  • Related