# calculate sum in associative array

## Recommended Posts

i have problem to get the sum from the associative array. i have to get sum for the 3 result that being display from the array

rsort(\$sub);
\$a=0;
\$arrlength = count(\$sub);
for(\$x = 0; \$x < 3; \$x++) {
echo \$sub[\$x];

}

##### Share on other sites

`\$a += \$sub[\$x];`

inside the for() loop woud accumulate the sum in \$a

##### Share on other sites

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 == {
\$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) {
}
if (\$high_res == 1) {
}
if (\$high_res == 2) {
}
if (\$high_res == 3) {
}
if (\$high_res == 4) {
}
if (\$high_res == 5) {
}
if (\$high_res == 6) {
}
if (\$high_res == 7) {
}
if (\$high_res == {
}
if (\$high_res == 9) {
}

}
else if (((\$sub == 'BM')  || (\$sub == 'BI') ||  (\$sub == 'SEJ') || (\$sub == 'PQS') || (\$sub == 'PSI')|| (\$sub == 'BAT')|| (\$sub == 'PI'))){//3 other subject
if (\$high_res == 0) {
}
if (\$high_res == 1) {
}
if (\$high_res == 2) {
}
if (\$high_res == 3) {
}
if (\$high_res == 4) {
}
if (\$high_res == 5) {
}
if (\$high_res == 6) {
}
if (\$high_res == 7) {
}
if (\$high_res == {
}
if (\$high_res == 9) {
}

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

echo  \$s[\$x];
// echo '<br>';

}

}

}
}

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 .

##### 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

##### 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])) {
}
elseif (in_array(\$sub, \$subjects[2])) {
}
}
rsort(\$s);
for(\$x = 0; \$x < 3; \$x++) {
echo  \$s[\$x].'<br>';
}

##### Share on other sites

Posted (edited)

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

Edited by ainbila
##### Share on other sites

On 6/26/2021 at 10:56 AM, Barand said:

```
\$a += \$sub[\$x];```

inside the for() loop woud accumulate the sum in \$a

only this time your array is "\$s" and not "\$sub".

##### Share on other sites

Posted (edited)
```

//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
##### Share on other sites

On 6/26/2021 at 2:18 PM, Barand said:

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

##### Share on other sites

Posted (edited)

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
##### Share on other sites

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

<!-- Site favicon -->

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

<!-- CSS -->

<!-- Global site tag (gtag.js) - Google Analytics -->
<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;
}
.ui-datepicker-calendar {
display: none;
}
</style>
<?php
session_start();
include_once 'talum.php';
error_reporting(E_ALL ^ E_NOTICE);

{

\$res=mysqli_query(\$dbconfig2,\$sql_query);
\$userRow=mysqli_fetch_array(\$res,MYSQLI_ASSOC);

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'){
}

?>

<body>

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

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

<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="row">
<div class="col-md-6 col-sm-12">
<div class="title">
<h4>DataTable</h4>
</div>
</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">
<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>
</tr>
<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'];

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

\$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;

foreach (\$subjects as \$subject) {

if(\$subject == 'BM'){
}elseif(\$subject == 'BI'){
}elseif(\$subject == 'MAT'){
}elseif(\$subject == 'SN'){
}elseif(\$subject == 'SEJ'){
}elseif(\$subject == 'KIM'){
}elseif(\$subject == 'BIO'){
}elseif(\$subject == 'FIZ'){
}elseif(\$subject == 'SNT'){
}elseif(\$subject == 'SPT'){
}elseif(\$subject == 'PJM'){
}elseif(\$subject == 'PJE'){
}elseif(\$subject == 'PJA'){
}elseif(\$subject == 'TKJ'){
}elseif(\$subject == 'TEK'){
}elseif(\$subject == 'LKJ'){
}elseif(\$subject == 'FOP'){
}elseif(\$subject == 'PDT'){
}elseif(\$subject == 'AKP'){
}else{

}

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

\$countSub = count(\$subjects);

//to count no if result

\$total_merit_mat= 0;
\$total_merit_fiz= 0;
\$total_merit_kim= 0;
\$merit = 0;
\$main_merit = 0;
\$main_merit1 =0 ;
\$total_merit = 0;
\$total_all_merit = 0;

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;
}

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

for(\$x = 0; \$x < 1; \$x++) {

if (\$x==3) break;

}
}

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;

//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;
}

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

for(\$x = 0; \$x < 1; \$x++) {

}
}

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;

//echo '<br>';
rsort(\$y);
\$arrlength = count(\$y);

for(\$x = 0; \$x < 3; \$x++) {

\$sum += \$y[\$x];

\$sum;

}

}

}

}

\$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 'window.href("index.php")';
echo 'window.location = "index.php"';
echo '</script>';
}
?>
```

##### Share on other sites

Posted (edited)

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...

Edited by Barand
##### Share on other sites

```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'  ?

## Join the conversation

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

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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

×
×

• #### Activity

• Chat
×
• Create New...