I think a little bit of optimization can be done using prepared statements:
...
// define the query with ? in places of variables
$query = "UPDATE registrar_grade_archive
SET grade = ?
WHERE student_id = ?
AND subject_id = ?
AND school_id = ?
AND advisor_faculty_id = ?
AND subject_handler_id = ?";
// prepare the query
$stmt = mysqli->prepare($query);
// loop through array of variables
foreach ($student_grades_boy as $key=>$data) {
$student_id_B= $data['studnt_B_id'];
$grade_B = $data['studnt_grade_B'];
// bind parameters to the query for each loop
// I assume here that all parameters are integers
$stmt -> bind_param(
"iiiiii", // set parameter types (all integers here)
$grade_B,
$student_id_B,
$subject_id,
$school_id,
$faculty_id,
$subject_handeler_id
);
// execute the query for this loop
$result = $stmt -> execute();
if(!$result) {
die ('Error updating the database.');
}
}
You get slighly better performance this way and quite a lot of security since prepared statements are great way of preventing injections.
Please note I have used the newer mysqli extension since the older mysql extension (which you are using) does not support prepared statements to my knowledge.
I haven't actually tested above code (since I am using PEAR MDB2 for cases like this) so please somebody have a look at it too and correct me if I am wrong.