 <?php
 require("../../config/koneksi.php");
require("../../config/function.php");
require("../../config/crud.php");
$qu = mysqli_query($koneksi, "select * from bk_siswa");
while ($bk = mysqli_fetch_array($qu)):
$siswa = mysqli_fetch_array(mysqli_query($koneksi, "SELECT nis,SUM(poin) AS total FROM bk_siswa WHERE nis='$bk[nis]'"));
	$query = mysqli_query($koneksi, "select * from bk_tindakan");
while ($tdk = mysqli_fetch_array($query)):

$min=$tdk['minpoin'];
$max=$tdk['maxpoin'];

$where =[
          'nis' => $siswa['nis'],     
           'ket' => $tdk['tindakan']    
         ];
      $cek = rowcount($koneksi, 'bk_sp', $where);
            if ($cek == 0) {
if($siswa['total'] >=$min  AND $tdk['tindakan']=='SP1'){
$exec = mysqli_query($koneksi, "INSERT INTO bk_sp(nis,ket,poin,tapel) VALUES('$siswa[nis]','$tdk[tindakan]','$siswa[total]','$setting[tp]')");
}
if($siswa['total'] >=$min  AND $tdk['tindakan']=='SP2'){
$exec = mysqli_query($koneksi, "INSERT INTO bk_sp(nis,ket,poin,tapel) VALUES('$siswa[nis]','$tdk[tindakan]','$siswa[total]','$setting[tp]')");
}
if($siswa['total'] >=$min  AND $tdk['tindakan']=='SP3'){
$exec = mysqli_query($koneksi, "INSERT INTO bk_sp(nis,ket,poin,tapel) VALUES('$siswa[nis]','$tdk[tindakan]','$siswa[total]','$setting[tp]')");
}
}
endwhile;
endwhile;
?>