I have a problem with the looping that iterates three times.Its been hours that i am looking solution why it loops trice.It might be the best idea to find help here to speed up my project.See the sample results below the expected output and the result with incorrect output.Hope anyone could help me here.Thank you in advance.
array:5 [▼
"1.4" => 40
"1.401" => 42
"1.5" => 38
]
array:5 [▼
"40" => 1.4
"42" => 1.4
"38" => 1.5
]
$count1 = 0;
$percentage = 1.1;
$last_scholar_gpa = 0;
foreach ($scho as $scholar_id2) {
foreach ($all_list_GPA as $scholar_GPA) {
$scholar = Scholar::find($scholar_id2);
$crits = New Criteria;
$crits->scholar_id = $scholar->scholar_id;
$crits->scholarship_id = $scholarship_id;
if ($last_scholar_gpa != $scholar_GPA) {
$percentage = $percentage - 0.1;
$total_points_two = $scholarship->scholarship_points_two * $percentage;
$crits->criteria_gpa = $total_points_two;
$last_scholar_gpa = $scholar_GPA;
}else{
$percentage = $percentage;
$total_points_two = $scholarship->scholarship_points_two * $percentage;
$crits->criteria_gpa = $total_points_two;
$last_scholar_gpa = $scholar_GPA;
}
$crits->save();
}
$count1++;
}
This is supposed to be the result:
id criteria_gpa
40 25.00
42 25.00
38 22.50
The current result which were saved in the database (but wrong computation)
id criteria_gpa
40 25.00
40 25.00
40 22.50
42 20.00
42 20.00
42 17.50
38 15.00
38 15.00
38 12.50
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire