Jump to content

calculate sum in associative array


ainbila

Recommended Posts

 

 

 

                    foreach(array_combine($subjects, $grades) as $sub => $res){


                    
                  if($aliran=='S'){
                     $sql4="SELECT * FROM `qualification_result` where st_aliran='S'";
                 $result4=mysqli_query($dbconfig,$sql4);
                  $row4=mysqli_fetch_array($result4,MYSQLI_ASSOC) ;
                    //$stEmail = $row4['st_email'];
                    //$stIC = $row3['st_ic'];
                    //$aliran1 = $row4['S'];
                   


                    if ($sub == 'MAT' || $sub == 'M-T' || $sub == 'FIZ' ||$sub == 'KIM'){


                      if ($res == 0) {
                        $merit = 18;
                      }
                      if ($res == 1) {
                        $merit = 16;
                      }
                      if ($res == 2) {
                        $merit = 14;
                      }
                      if ($res == 3) {
                        $merit = 12;
                      }
                      if ($res == 4) {
                        $merit = 10;
                      }
                      if ($res == 5) {
                        $merit = 8;
                      }
                      if ($res == 6) {
                        $merit = 6;
                      }
                      if ($res == 7) {
                        $merit = 4;
                      }
                      if ($res == 8) {
                        $merit = 2;
                      }
                      if ($res == 9) {
                        $merit = 0;
                      }

                      $main_merit+= $merit;
                    } 
//to select high mark for 5th subject
                    $high_res = min(array($res));
                    
                    if ((($sub == 'SNT') || ($sub == 'BIO') || ($sub == 'GRA') || ($sub == 'GKT') || ($sub == 'TEK') || ($sub == 'LKJ') || ($sub == 'PJA') || ($sub == 'PJE') || ($sub == 'PJM') || ($sub == 'PSS') || ($sub == 'PEE') || ($sub == 'MUL') || ($sub == 'PDT') || ($sub == 'RKB') || ($sub == 'RT') || ($sub == 'SS')) && (($sub != 'MAT') || ($sub != 'M-T') || ($sub != 'FIZ') || ($sub != 'KIM'))){
                      if ($high_res == 0) {
                        $meritAdd = 18;
                      }
                      if ($high_res == 1) {
                        $meritAdd = 16;
                      }
                      if ($high_res == 2) {
                        $meritAdd = 14;
                      }
                      if ($high_res == 3) {
                        $meritAdd = 12;
                      }
                      if ($high_res == 4) {
                        $meritAdd = 10;
                      }
                      if ($high_res == 5) {
                        $meritAdd = 8;
                      }
                      if ($high_res == 6) {
                        $meritAdd = 6;
                      }
                      if ($high_res == 7) {
                        $meritAdd = 4;
                      }
                      if ($high_res == 8) {
                        $meritAdd = 2;
                      }
                      if ($high_res == 9) {
                        $meritAdd = 0;
                      }
                      $main_add_merit = $meritAdd;
                      
                 
                    }
else if ((($sub == 'BM')  || ($sub == 'BI') ||  ($sub == 'SEJ') || ($sub == 'PQS') || ($sub == 'PSI')|| ($sub == 'BAT')|| ($sub == 'PI'))){//3 other subject
                      if ($high_res == 0) {
                        $meritAdd = 18;
                      }
                      if ($high_res == 1) {
                        $meritAdd = 16;
                      }
                      if ($high_res == 2) {
                        $meritAdd = 14;
                      }
                      if ($high_res == 3) {
                        $meritAdd = 12;
                      }
                      if ($high_res == 4) {
                        $meritAdd = 10;
                      }
                      if ($high_res == 5) {
                        $meritAdd = 8;
                      }
                      if ($high_res == 6) {
                        $meritAdd = 6;
                      }
                      if ($high_res == 7) {
                        $meritAdd = 4;
                      }
                      if ($high_res == 8) {
                        $meritAdd = 2;
                      }
                      if ($high_res == 9) {
                        $meritAdd = 0;
                      }
                      $main_add_merit1 = $meritAdd;
                      //echo $main_add_merit1;
                      //sort ($main_add_merit1);

                      $s[$i] = $main_add_merit1;
$i++;
                $s[$i];
                // echo '<br>';
rsort($s);
$arrlength = count($s);
for($x = 0; $x < 3; $x++) {
 
echo  $s[$x];
 // echo '<br>';

  

}
    
                  } $total =$main_merit+$main_add_merit;
}


 }
 } 

 

is the way i put loop is wrong? because it get looping everytime and user does not get their result . i have to display merit for 5 main subject and it done .but when i have to display sum of 3 other subject,the looping get me wrong .

error.PNG

Link to comment
Share on other sites

When posting code, use the <> button in the toolbar.

Do not run queries inside loops.

1 hour ago, ainbila said:

i have to display merit for 5 main subject and it done .but when i have to display sum of 3 other subject

From looking at the code there appear to be 4 main subjects and 16 other ones.

The whole code really is in need of a major rewrite.

If i knew

  • what was in the $subjects and $grades arrays, and
  • the structure and content of your qualification_result table (and related tables)
  • what the output should look like

I could help you with that.

Link to comment
Share on other sites

P.S.

I am not sure what you want to do with the query results so I have omitted that.

Also not sure what $high_res is supposed to be. Currently it ill always be the same as $res.

But if you make use of a couple of arrays, your code reduces to something like this

$subjects = [ [ 'MAT', 'M-T', 'FIZ', 'KIM' ],
              [ 'SNT', 'BIO', 'GRA', 'GKT', 'TEK', 'LKJ', 'PJA', 'PJE', 'PJM', 'PSS', 'PEE', 'MUL', 'PDT', 'RKB', 'RT', 'SS' ],
              [ 'BM', 'BI', 'SEJ', 'PQS', 'PSI', 'BAT', 'PI' ]
            ];
$merits   = [ 18, 16, 14, 12, 10, 8, 6, 4, 2, 0 ];
            
foreach(array_combine($subjects, $grades) as $sub => $res){
    if (in_array($sub, $subjects[0])) {
        $main_merit += $merits[$res];
    }
    elseif (in_array($sub, $subjects[1])) {
        $main_add_merit = $merits[$res];
    }
    elseif (in_array($sub, $subjects[2])) {
        $main_add_merit1 = $merits[$res];
    }
    $si[] = $main_add_merit1;
}
rsort($s);
for($x = 0; $x < 3; $x++) {
    echo  $s[$x].'<br>';
}
$total =$main_merit+$main_add_merit;

 

Link to comment
Share on other sites

thank you for the suggestion .i will try to change . but , for now i have problem to calculate the array sum in the for loop 3 .. right now the result appear like 161210 ,i want it to sum like total=16+12+10 

sort.PNG

Edited by ainbila
Link to comment
Share on other sites


                      $main_add_merit1 = $merit;
                    

                       $s[$i] = $main_add_merit1;
                       //echo '<br>';
                       $sum=0;
 rsort($s);
$arrlength = count($s);
 

 //foreach ($s as $si){
for($x = 0; $x < 3; $x++) {


 $sum += $s[$x];
             }       
    

                  
}

i'got the value  3 sum . but right now , it stop the value on third student . so the fourth and after ,they getting value from third student .i only want calculate 3 first value form sorting . seems it also stop for third student . and getting looping weirdly .can you help me with that 

Edited by ainbila
Link to comment
Share on other sites

so , subject  is sub() and grade(res)  like above ..and i have to get merit total based on condition . the merit value is based on the grade

1) i have to get merit for 4 main subject like in the first  if else

2) in second if else , i have to get the 1 higher/maximum subject gred and get the merit

3)in third if else , i have to get total merit from 3 other maximum/gred subject than in first and second if else.

4) lastly , total 5 subject merit (4 subject from first if else +1 subject from second if else) + total merit from  3 other maximum/gred subject / sum =5+3

Edited by ainbila
Link to comment
Share on other sites

<!DOCTYPE html>
<html>
<head>
  <!-- Basic Page Info -->
  <meta http-equiv="refresh" content="900;url=index.php" />
  <meta charset="utf-8">
  <title>Student Admission</title>

  <!-- Site favicon -->
  <link rel="apple-touch-icon" sizes="180x180" href="vendors/images/apple-touch-icon.png">
  <link rel="icon" type="image/png" sizes="32x32" href="vendors/images/favicon-32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="vendors/images/favicon-16x16.png">


  <!-- Mobile Specific Metas -->
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

  <!-- Google Font -->
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
  <!-- CSS -->
  <link rel="stylesheet" type="text/css" href="vendors/styles/core.css">
  <link rel="stylesheet" type="text/css" href="vendors/styles/icon-font.min.css">
  <link rel="stylesheet" type="text/css" href="src/plugins/jquery-steps/jquery.steps.css">
  <link rel="stylesheet" type="text/css" href="vendors/styles/style.css">
  <link rel="stylesheet" href="src/styles/yearpicker.css">
  <link rel="stylesheet" type="text/css" href="src/plugins/datatables/css/dataTables.bootstrap4.min.css">
  <link rel="stylesheet" type="text/css" href="src/plugins/datatables/css/responsive.bootstrap4.min.css">

  <!-- Global site tag (gtag.js) - Google Analytics -->
  <script async src="https://www.googletagmanager.com/gtag/js?id=UA-119386393-1"></script>
  <script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());

    gtag('config', 'UA-119386393-1');
  </script>
  <style>
    .float{
      position:fixed;

      bottom:70px;
      right:70px;


      text-align:center;
      box-shadow: 2px 2px 3px #999;
    }
    .ui-datepicker-calendar {
      display: none;
    }
  </style>
</head>
<?php
session_start();
include_once 'talum.php';
error_reporting(E_ALL ^ E_NOTICE);

if(isset($_SESSION['login_username']))
{
  $login_session=$_SESSION['login_username'];

  $sql_query="SELECT * FROM master_admission_login WHERE login_username = '$login_session' ";
  $res=mysqli_query($dbconfig2,$sql_query);
  $userRow=mysqli_fetch_array($res,MYSQLI_ASSOC);
  $userUsername = $userRow['login_username'];
  
  $userName = $userRow['login_name'];
  $userRole = $userRow['login_role'];

  date_default_timezone_set("asia/kuala_lumpur");
  $thisyear = date('Y');
  $nextyear = date('Y')+1;

  $appAgentId = $_REQUEST['id'];

  if($userRole=='agent'){
    $sql="SELECT * FROM application_agent_info WHERE id = '$appAgentId'";
    $result=mysqli_query($dbconfig,$sql);
    $row=mysqli_fetch_array($result,MYSQLI_ASSOC);
    $studentEmail = $row['std_email'];
    $studentIC = $row['std_ic'];
  }else if($userRole=='student'){
    $studentEmail = $userUsername;
  }



  

  ?>

<body>
    
    <!--header-->
    <?php include("header.php"); ?> 

    <!--right_side-->
    <?php include("right_side.php"); ?>

    <!--left_side-->
    <?php include("left_side.php"); ?>

    <div class="mobile-menu-overlay"></div>
    
    
    <div class="main-container">
      <div class="pd-ltr-20 xs-pd-20-10">
        <form action="stdUpdate.php" method="POST" enctype="multipart/form-data">
          <div class="min-height-200px">
            <div class="page-header">
        <div class="row">
          <div class="col-md-6 col-sm-12">
            <div class="title">
              <h4>DataTable</h4>
            </div>
            <nav aria-label="breadcrumb" role="navigation">
              <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="index.html">Home</a></li>
                <li class="breadcrumb-item active" aria-current="page">List Student</li>
              </ol>
            </nav>
          </div>
          
        </div>
      </div>
      <!-- Export Datatable start -->
        <div class="card-box mb-30">
          <div class="pd-20">
            <h4 class="text-blue h4">List of Application</h4>
          </div>
          <div class="pb-20">
            <table class="table hover multiple-select-row data-table-export nowrap">
              <thead>
                <tr>
                  <th class="table-plus datatable-nosort">No</th>
                  <th>Name</th>
                  <th>IC No</th>
                  <th>aliran</th>
                  <!--th>First Choice</th>
                  <th>Date Application</th-->
                  <th>Program</th>
                  <th>Markah MP Utama Aliran  </th>
                  <th>Markah MP Terbaik</th>
                   <th>Markah Akademik</th>
                </tr>
              </thead>
              <tbody>



  
<?php




 

        $sql3="SELECT DISTINCT * FROM application_pda inner join application_program on application_pda.au_ic=application_program.st_ic where application_program.first_choice='DIP'  ";

        $app=mysqli_query($dbconfig,$sql3);
  
        

        while($row=mysqli_fetch_array($app,MYSQLI_ASSOC)){
        


          $id = $row['au_id'];
          $email = $row['au_email'];
          $ic= $row['au_ic'];
          $name = $row['au_name'];


          $sql="SELECT * FROM application_pda INNER JOIN qualification_result where qualification_result.st_ic = '$ic' AND application_pda.au_ic = qualification_result.st_ic  and qualification_result.new_entry_quali='2' ";

          $sql2 = "SELECT * FROM application_program  WHERE st_ic = '$ic'";
          $program_Result=mysqli_query($dbconfig,$sql2);
          $row2=mysqli_fetch_array($program_Result,MYSQLI_ASSOC);




          $first = $row2["first_choice"];
          $second = $row2["second_choice"];
          $third = $row2["third_choice"];
          $firstList = $row2['firstList'];
          $offer = 0;

          $result=mysqli_query($dbconfig,$sql);
          $row1=mysqli_fetch_array($result,MYSQLI_ASSOC);
          $subject = $row1['qr_subject'];
          $aliran = $row1['st_aliran'];
          //$grade = $row1['qr_result'];
                    $grade = $row1['qr_spm_result'];



          $subjects = (explode(",",$subject));

          $grades = (explode(",",$grade));
          //$grades1 = (explode(",",$grade1));

          $BM = 8;
          $BI = 8;
          $MAT = 8;
          $SN = 8;
          $SEJ = 8;
          $KIM = 8;
          $BIO = 8;
          $FIZ = 8;
          $SNT = 8;
          $SN = 8;
          $SPT = 8;
          $PJM = 8;
          $PJE = 8;
          $PJA = 8;
          $TKJ = 8;
          $TEK = 8;
          $LKJ = 8;
          $FOP = 8;
          $PDT = 8;
          $AKP = 8;



          $i = 0;

          
              

          if ($grade != NULL){

          foreach ($subjects as $subject) {
           
            if($subject == 'BM'){
              $BM = $grades[$i];
                    //echo 'BM = '.$grades[$i];
            }elseif($subject == 'BI'){
              $BI = $grades[$i];
                    //echo 'BI = '.$grades[$i];
            }elseif($subject == 'MAT'){
              $MAT = $grades[$i];
                    //echo 'MAT = '.$grades[$i];
            }elseif($subject == 'SN'){
              $SN = $grades[$i];
                    //echo 'SN = '.$grades[$i];
            }elseif($subject == 'SEJ'){
              $SEJ = $grades[$i];
                    //echo 'SEJ = '.$grades[$i];
            }elseif($subject == 'KIM'){
              $KIM = $grades[$i];
                    //echo 'KIM = '.$grades[$i];
            }elseif($subject == 'BIO'){
              $BIO = $grades[$i];
                    //echo 'BIO = '.$grades[$i];
            }elseif($subject == 'FIZ'){
              $FIZ = $grades[$i];
            }elseif($subject == 'SNT'){
              $SNT = $grades[$i];
                    //echo 'SNT = '.$grades[$i];
            }elseif($subject == 'SPT'){
              $SPT = $grades[$i];
                    //echo 'SPT = '.$grades[$i];
            }elseif($subject == 'PJM'){
              $PJM = $grades[$i];
                    //echo 'PJM = '.$grades[$i];
            }elseif($subject == 'PJE'){
              $PJE = $grades[$i];
                    //echo 'PJE = '.$grades[$i];
            }elseif($subject == 'PJA'){
              $PJA = $grades[$i];
                    //echo 'PJA = '.$grades[$i];
            }elseif($subject == 'TKJ'){
              $TKJ = $grades[$i];
                    //echo 'TKJ = '.$grades[$i];
            }elseif($subject == 'TEK'){
              $TEK = $grades[$i];
                    //echo 'TEK = '.$grades[$i];
            }elseif($subject == 'LKJ'){
              $LKJ = $grades[$i];
                    //echo 'LKJ = '.$grades[$i];
            }elseif($subject == 'FOP'){
              $FOP = $grades[$i];
                    //echo 'FOP = '.$grades[$i];
            }elseif($subject == 'PDT'){
              $PDT = $grades[$i];
                    //echo 'PDT = '.$grades[$i];
            }elseif($subject == 'AKP'){
              $AKP = $grades[$i];
                    //echo 'AKP = '.$grades[$i];
            }else{
              
            }


            $i++;
          }
        }else {
'';}


                 
                    
              
                    
                    $countSub = count($subjects);
                    
                    //$results = (explode(",",$grades));
                     //to count no if result
                    $countRes = count($grades)-1;
                   
                    
                    $total_merit_mat= 0;
                    $total_merit_addmath = 0;
                    $total_merit_fiz= 0;
                    $total_merit_kim= 0;
                    $merit = 0;
                    $main_merit = 0;
                    $main_merit1 =0 ;
                    $main_add_merit = 0;
                    $total_merit = 0;
                    $total_all_merit = 0;
                   
                     //$meritAdd = 0;
                   
                    if(count($subjects) == count($grades)){

                    foreach(array_combine($subjects, $grades) as $sub => $res){


                    
                  if($aliran=='S'){
                     $sql4="SELECT * FROM `qualification_result` where st_aliran='S'";
                 $result4=mysqli_query($dbconfig,$sql4);
                  $row4=mysqli_fetch_array($result4,MYSQLI_ASSOC) ;
                    //$stEmail = $row4['st_email'];
                    //$stIC = $row3['st_ic'];
                    //$aliran1 = $row4['S'];
                   

                
                    if (($sub == 'MAT') || ($sub == 'M-T') || ($sub == 'FIZ') || ($sub == 'KIM'))  {
                      if ($res == 0) {
                        $merit = 18;
                      }
                      if ($res == 1) {
                        $merit = 16;
                      }
                      if ($res == 2) {
                        $merit = 14;
                      }
                      if ($res == 3) {
                        $merit = 12;
                      }
                      if ($res == 4) {
                        $merit = 10;
                      }
                      if ($res == 5) {
                        $merit = 8;
                      }
                      if ($res == 6) {
                        $merit = 6;
                      }
                      if ($res == 7) {
                        $merit = 4;
                      }
                      if ($res == 8) {
                        $merit = 2;
                      }
                      if ($res == 9) {
                        $merit = 0;
                      }
                      
                      $main_merit += $merit;
                      
                    }

   //to select high mark for 5th subject
                    
                    else if (($sub == 'SNT') || ($sub == 'LKJ') || ($sub == 'GRA') || ($sub == 'GKT') || ($sub == 'TEK') || ($sub == 'PJA') || ($sub == 'BIO') || ($sub == 'PJE') || ($sub == 'PJM') || ($sub == 'PSS') || ($sub == 'PEE') || ($sub == 'MUL') || ($sub == 'PDT') || ($sub == 'RKB') || ($sub == 'RT') || ($sub == 'SS')){
                       if ($res == 0) {
                        $merit = 18;
                      }
                      if ($res == 1) {
                        $merit = 16;
                      }
                      if ($res == 2) {
                        $merit = 14;
                      }
                      if ($res == 3) {
                        $merit = 12;
                      }
                      if ($res == 4) {
                        $merit = 10;
                      }
                      if ($res == 5) {
                        $merit = 8;
                      }
                      if ($res == 6) {
                        $merit = 6;
                      }
                      if ($res == 7) {
                        $merit = 4;
                      }
                      if ($res == 8) {
                        $merit = 2;
                      }
                      if ($res == 9) {
                        $merit = 0;
                      }

                      $main_add_merit = $merit;
 $k[$i] = $merit;
rsort($k);
$arrlength = count($k);

for($x = 0; $x < 1; $x++) {
 
 if ($x==3) break;
 $main_add_merit=$k[$x];

 $main_add_merit;
  
                    
                      
                    }
}
            
                
  

                   if ((($sub == 'BM')  || ($sub == 'BI') ||  ($sub == 'SEJ') || ($sub == 'PQS') || ($sub == 'PSI')|| ($sub == 'BAT')|| ($sub == 'PI'))){
                      if ($res == 0) {
                        $merit = 18;
                      }
                      if ($res == 1) {
                        $merit = 16;
                      }
                      if ($res == 2) {
                        $merit = 14;
                      }
                      if ($res == 3) {
                        $merit = 12;
                      }
                      if ($res == 4) {
                        $merit = 10;
                      }
                      if ($res == 5) {
                        $merit = 8;
                      }
                      if ($res == 6) {
                        $merit = 6;
                      }
                      if ($res == 7) {
                        $merit = 4;
                      }
                      if ($res == 8) {
                        $merit = 2;
                      }
                      if ($res == 9) {
                        $merit = 0;
                      }


                    $sum=0;

                      $main_add_merit1 = $merit;
                    

                       $s[$i] = $main_add_merit1;
                       //echo '<br>';
                       rsort($s);
$arrlength = count($s);

for($x = 0; $x < 3; $x++) {
 
 $sum += $s[$x];

   


                    } 
 

}


 
 

} 
                  else if($aliran=='A'){
                     $sql4="SELECT * FROM `qualification_result` where st_aliran='S'";
                 $result4=mysqli_query($dbconfig,$sql4);
                  $row4=mysqli_fetch_array($result4,MYSQLI_ASSOC) ;
                    //$stEmail = $row4['st_email'];
                    //$stIC = $row3['st_ic'];
                    //$aliran1 = $row4['S'];
                   

                
                    if (($sub == 'BM') || ($sub == 'MAT') || ($sub == 'SN') || ($sub == 'SEJ'))   {
                      if ($res == 0) {
                        $merit = 18;
                      }
                      if ($res == 1) {
                        $merit = 16;
                      }
                      if ($res == 2) {
                        $merit = 14;
                      }
                      if ($res == 3) {
                        $merit = 12;
                      }
                      if ($res == 4) {
                        $merit = 10;
                      }
                      if ($res == 5) {
                        $merit = 8;
                      }
                      if ($res == 6) {
                        $merit = 6;
                      }
                      if ($res == 7) {
                        $merit = 4;
                      }
                      if ($res == 8) {
                        $merit = 2;
                      }
                      if ($res == 9) {
                        $merit = 0;
                      }
                      
                      $main_merit += $merit;
                      
                    }

   //to select high mark for 5th subject
                    
                    
                    else if ((($sub == 'PI') || ($sub == 'PM') || ($sub == 'PQS') || ($sub == 'PSI') || ($sub == 'HQ') || ($sub == 'MQ')) ){
                       if ($res == 0) {
                        $merit = 18;
                      }
                      if ($res == 1) {
                        $merit = 16;
                      }
                      if ($res == 2) {
                        $merit = 14;
                      }
                      if ($res == 3) {
                        $merit = 12;
                      }
                      if ($res == 4) {
                        $merit = 10;
                      }
                      if ($res == 5) {
                        $merit = 8;
                      }
                      if ($res == 6) {
                        $merit = 6;
                      }
                      if ($res == 7) {
                        $merit = 4;
                      }
                      if ($res == 8) {
                        $merit = 2;
                      }
                      if ($res == 9) {
                        $merit = 0;
                      }

                      $main_add_merit = $merit;
 $l[$i] = $merit;
rsort($l);
$arrlength = count($l);

for($x = 0; $x < 1; $x++) {
 
 $main_add_merit=$l[$x];

 $main_add_merit;
  
                    
                      
                    }
}
            
                


                  else if (($sub == 'BI') || ($sub == 'TSI') || ($sub == 'PAP') || ($sub == 'PAK'))  {
                      if ($res == 0) {
                        $merit = 18;
                      }
                      if ($res == 1) {
                        $merit = 16;
                      }
                      if ($res == 2) {
                        $merit = 14;
                      }
                      if ($res == 3) {
                        $merit = 12;
                      }
                      if ($res == 4) {
                        $merit = 10;
                      }
                      if ($res == 5) {
                        $merit = 8;
                      }
                      if ($res == 6) {
                        $merit = 6;
                      }
                      if ($res == 7) {
                        $merit = 4;
                      }
                      if ($res == 8) {
                        $merit = 2;
                      }
                      if ($res == 9) {
                        $merit = 0;
                      }


                    $sum=0;

                      $main_add_merit1 = $merit;
                    

                       $y[$i] = $main_add_merit1;
                       //echo '<br>';
                       rsort($y);
$arrlength = count($y);

for($x = 0; $x < 3; $x++) {
 
 $sum += $y[$x];

 
  $sum;



                    } 
 



} 
 
 

}



}

  

 
 $total = $main_merit+$main_add_merit;

$total1 = $sum+$total; 
 }



    
              
 

          if(!empty($firstList)){
            $firstLists = (explode(",",$firstList));

            $program = NULL;

            foreach ($firstLists as $firstList) {
              
              if($first=='DIP'){
                $sql_DIP="SELECT * FROM program_diploma WHERE pg_code='$firstList'";
                $resultDCode=mysqli_query($dbconfig3,$sql_DIP); 
                $row=mysqli_fetch_array($resultDCode,MYSQLI_ASSOC);

                if($program == NULL){       
                  if ($firstList == 'DMM') {
                    if(($BM <= 6) && ($MAT <= 6) && ($BI <= 8) && ($SEJ <= 8) &&  (($SN <= 6) || ($FIZ <= 6) || ($KIM <= 6)  || ($BIO <= 6) || ($SNT <= 6) || ($SPT <= 6) || ($PJM <= 6) || ($PJE <= 6) || ($PJA <= 6) || ($TKJ <= 6) || ($TEK <= 6 || ($LKJ <= 6)))){
                      $pgName=$row['pg_name'];
                      $program = $pgName;
            //$program = 'Diploma In Mechanical Engineering <br>';
                      $programCode = '01';
                    }else{
                      $program ='';
                    }
                  }elseif($firstList == 'DKC'){
                    if(($BM <= 6) && ($MAT <= 6) && ($BI <= 8) && ($SEJ <= 8) &&  (($SN <= 6) || ($FIZ <= 6) || ($KIM <= 6)  || ($BIO <= 6) || ($SNT <= 6) || ($SPT <= 6) || ($PJM <= 6) || ($PJE <= 6) || ($PJA <= 6) || ($TKJ <= 6) || ($TEK <= 6 || ($LKJ <= 6)))){
                      $pgName=$row['pg_name'];
                      $program = $pgName;
            //$program = 'Diploma In Chemical Engineering <br>';
                      $programCode = '01';
                    }else{
                      $program ='';
                    }
                  }elseif($firstList == 'DAA'){
                    if(($BM <= 6) && ($MAT <= 6) && ($BI <= 8) && ($SEJ <= 8) &&  (($SN <= 6) || ($FIZ <= 6) || ($KIM <= 6) || ($BIO <= 6) || ($SNT <= 6) || ($SPT <= 6) || ($PJM <= 6) || ($PJE <= 6) || ($PJA <= 6) || ($TKJ <= 6) || ($TEK <= 6 || ($LKJ <= 6)))){
                      $pgName=$row['pg_name'];
                      $program = $pgName;
            //$program = 'Diploma In Civil Engineering <br>';
                      $programCode = '01';
                    }else{
                      $program ='';
                    }
                  }elseif($firstList == 'DEE'){
                    if(($BM <= 6) && ($MAT <= 6) && ($BI <= 8) && ($SEJ <= 8) &&  (($SN <= 6) || ($FIZ <= 6) || ($KIM <= 6) || ($BIO <= 6) || ($SN <= 6) || ($SNT <= 6) || ($SPT <= 6) || ($PJM <= 6) || ($PJE <= 6) || ($PJA <= 6) || ($TKJ <= 6) || ($TEK <= 6 || ($LKJ <= 6)))){
                      $pgName=$row['pg_name'];
                      $program = $pgName;
            //$program = 'Diploma In Electric Engineering (industrial Electronic) <br>';  
                      $programCode = '01';
                    }else{
                      $program ='';
                    }
                  }elseif($firstList == 'DCS'){
                    if(($BM <= 6) && ($MAT <= 6) && ($BI <= 8) && ($SEJ <= 8) && (($SN <= 8) || ($KIM <= 6) || ($BIO <= 6) || ($SN <= 6) || ($SNT <= 6) || ($SPT <= 6) || ($PJM <= 6) || ($PJE <= 6) || ($PJA <= 6) || ($TKJ <= 6) || ($TEK <= 6) || ($LKJ <= 6) || ($FOP <= 6) || ($PDT <= 6) || ($AKP <= 6))){
                      $pgName=$row['pg_name'];
                      $program = $pgName;
            //$program = 'Diploma In Computer Science <br>';
                      $programCode = '01';
                    }else{
                      $program ='';
                    }
                  }elseif($firstList == 'DPS'){
                    if(($BM <= 6) && ($BI <= 8) && ($SEJ <= 8) && (($MAT <= 6) || ($KIM <= 6) || ($BIO <= 6) || ($SN <= 6) || ($SNT <= 6) || ($FIZ <= 6))){
                      $pgName=$row['pg_name'];
                      $program = $pgName;
            //$program = 'Diploma In Safety And Health <br>';
                      $programCode = '01';
                    }else{
                      $program ='';
                    }
                  }
                }






              }

            }
          }
            ?> 










<tr>
                  <td class="table-plus"></td>
                  <td><?php echo strtoupper($name)?></td>
                  <td><?php echo $ic?></td>
                  <td><?php echo $aliran?></td>
                  <!--td><?//php echo strtoupper($FirstList)?></td-->
                  <!--td><?//php echo $stAppDate?></td-->
                  <td><?php echo $program?></td>
                  <td><?php echo $total?></td>
                  <td><?php echo $sum?></td>
                    <td><?php echo $total1?></td>
                     
                                  
                </tr>
              <?php
                  }
              ?>


</tbody>
            </table>
          </div>
        </div>
            
        </div>
        </form>
        <!--footer-->
        <?php include("footer.php"); ?> 
      </div>
    </div>



!-- js -->
    <script src="vendors/scripts/core.js"></script>
  <script src="vendors/scripts/script.min.js"></script>
  <script src="vendors/scripts/process.js"></script>
  <script src="vendors/scripts/layout-settings.js"></script>
  <script src="src/plugins/datatables/js/jquery.dataTables.min.js"></script>
  <script src="src/plugins/datatables/js/dataTables.bootstrap4.min.js"></script>
  <script src="src/plugins/datatables/js/dataTables.responsive.min.js"></script>
  <script src="src/plugins/datatables/js/responsive.bootstrap4.min.js"></script>
  <!-- buttons for Export datatable -->
  <script src="src/plugins/datatables/js/dataTables.buttons.min.js"></script>
  <script src="src/plugins/datatables/js/buttons.bootstrap4.min.js"></script>
  <script src="src/plugins/datatables/js/buttons.print.min.js"></script>
  <script src="src/plugins/datatables/js/buttons.html5.min.js"></script>
  <script src="src/plugins/datatables/js/buttons.flash.min.js"></script>
  <script src="src/plugins/datatables/js/pdfmake.min.js"></script>
  <script src="src/plugins/datatables/js/vfs_fonts.js"></script>
  <!-- Datatable Setting js -->
  <script src="vendors/scripts/datatable-setting.js"></script>



</body>
<?php

} 






 

else {
  echo '<script>';  
  echo 'alert("Session expired. Please login again.")';
  //echo 'window.href("index.php")';
  echo 'window.location = "index.php"';
  echo '</script>';
}
?>

 

Link to comment
Share on other sites

Interesting.

Not only does the code need a rewrite (as I mentioned before) but I can now see the whole database needs rebuilding.

Database tables should be normalized, (Google it) not populated with comma-separated lists. If you design the database correctly (so it supports the application), the coding gets a whole lot simpler, removing the need for those dozens of "if" conditions.

(there is a tutorial link in my signature, which just happens to be based on students and results, that should give you a guide)

[edit...]

PS the DB should also eliminate duplicated and conflicting conditions...

image.thumb.png.b84741335c67f92030c631598ddb2b05.png

Edited by Barand
Link to comment
Share on other sites

Within your subject/grade loop you have two sections

if($aliran=='S'){
    $sql4="SELECT * FROM `qualification_result` where st_aliran='S'";

then

else if($aliran=='A'){
    $sql4="SELECT * FROM `qualification_result` where st_aliran='S'";

Should they both have where st_aliran='S' or should the second be where st_aliran='A'  ?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.