How to change my update.php with X-editable datatable when i update 1 cell will change 2 cell in the same row

41 Views Asked by At

I have database with X-editable datatable

|Id|Id Student|Id Course|Score|Grade|

and this my update.php

<?php

//update.php

$connect = new PDO("mysql:host=localhost;dbname=siakad", "root", "");
$konek = mysqli_connect("localhost", "root", "", "siakad");
    
if(mysqli_connect_error()){
    printf ("Gagal terkoneksi : ".mysqli_connect_error());
    exit();
}
    
include "auth_user.php";

function grade($score)
{
 if($score <= 100 ) { $grade = "A";}
 if($score <  80 )  { $grade = "B";}
 if($score <  70 )  { $grade = "C";}
 if($score <  60 )  { $grade = "D";}
 if($score <  50 )  { $grade = "E";}

 return $grade;
}

function mutu($grade)
{
 if($grade =  "A" )  { $mutu = "4";}
 if($grade =  "B" )  { $mutu = "3";}
 if($grade =  "C" )  { $mutu = "2";}
 if($grade =  "D" )  { $mutu = "1";}
 if($grade =  "E" )  { $mutu = "0";}

 return $mutu;
}

$jeneng= $_POST["name"];

if ($jeneng == "Score"){
    $querysks= ($konek, "SELECT SKS_krs FROM krs WHERE Id_krs ='".$_POST["pk"]."'");
    while ($sks = mysqli_fetch_array ($querysks)){
        $SKSa=$sks['SKS_krs'];}
    $nilai= $_POST["value"];
    $grade = grade($score);
    $mutu  = mutu($grade);
    $hasil = $SKSa * $mutu;
    $query = "UPDATE krs SET ".$_POST["name"]." = '".$_POST["value"]."', Grade = '".$grade."' WHERE Id_krs = '".$_POST["pk"]."';"
    $connect->query($query);
}
else
{
    $query = "
UPDATE krs
SET ".$_POST["name"]." = '".$_POST["value"]."' 
WHERE Id_krs = '".$_POST["pk"]."'
";

$connect->query($query);
}
?>

I just want change if i change the score 75 and the table change the score "75" and grade "B", anyone can help me with my trouble

0

There are 0 best solutions below