1 回答
TA贡献1820条经验 获得超10个赞
最好迭代分数,然后迭代评分以找到分数所属的分数。
此外,您的 if 没有大括号,因此它将仅执行它之后的第一个句子。
// fetches the grading system whose array is seen below
while ($row = $grade->fetch(PDO::FETCH_ASSOC)) {
$data = $row;
// var_export($data); // No need to se this anymore
}
// fetches scores of students in test
while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
$scores = $row;
// var_export($scores); // No need to see this anymore
}
// Iterate scores first (I don't know if you need the index or not)
foreach($scores as $scoreIndex => $score) {
// Search grading for this score (Index not needed here, just values)
foreach($data as $grading) {
if($score['marks'] >= $grading['grade_min'] && $score['marks'] <= $grading['grade_max']) {
// Score is inside this grading
// Echo, print or assign what you need here
// Then exit the loop for grading
break;
}
}
}
根据 的输出,该数组只是一个值,没有关联数组,因此循环应为:$scores
// Iterate scores first (I don't know if you need the index or not)
foreach($scores as $scoreIndex => $score) {
// Search grading for this score (Index not needed here, just values)
foreach($data as $grading) {
// $score is an integer, not an array
if($score >= $grading['grade_min'] && $score <= $grading['grade_max']) {
// Score is inside this grading
// Echo here what you need
// Then exit the loop for grading
break;
}
}
}
- 1 回答
- 0 关注
- 95 浏览
添加回答
举报