Exiting a loop when a condition occurs and excluding the use of its given db value

Assuming a student takes 6 courses per semester. All of these yards have units of slope (int), and depending on the grade in each course there are points.

so a score >=70 will have a point of 5 <70 and >=60 will have a ponit of 4 

etc. For each unit of course, points are multiplied together, down the column for each column. Now that the course grade is not found, class "AR". Now I want the loops to omit the appearance of AR..ie without adding a course unit that has a grade of "AR". But when I start my queries over units, I still add to the general units of the course.

Query4 is used to create multiple course_unit and grade lines .

  $query4 = mysql_query("SELECT c.course_unit, m.score FROM maintable AS m INNER JOIN students AS s ON m.matric_no = s.matric_no INNER JOIN courses AS c ON m.course_code = c.course_code WHERE m.matric_no = '".$matric_no."' AND m.level = '".$level."'") or die (mysql_error()); 

Query3 is used to summarize course_units

  $query3 = mysql_query("SELECT SUM(c. course_unit) AS 'TOTAL' FROM maintable AS m INNER JOIN students AS s ON m.matric_no = s.matric_no INNER JOIN courses AS c ON m.course_code = c.course_code WHERE m.matric_no = '".$matric_no."' AND m.level = '".$level."'") or die (mysql_error()); 

Grades in relation to grades

  while ($row8 = mysql_fetch_assoc ($query8)) { if ($row8['score'] >= 70) { $grade = 'A'; } elseif ($row8['score'] >= 60) { $grade = 'B'; }elseif ($row8['score'] >= 50) { $grade = 'C'; }elseif ($row8['score'] >= 45) { $grade = 'D'; }elseif($row8['score'] >= 40) { $grade = 'E'; }elseif($row8['score'] >= 0) && ($row8['score'] < 40){ $grade = 'F'; }else{ $grade = 'AR'; } } 

Assessment Point Calculation

  $grade_point = 0; while ($row4 = mysql_fetch_assoc($query4)) { if ($row4['score'] >= 70) { $score = 5; } elseif ($row4['score'] >= 60) { $score = 4; }elseif ($row4['score'] >= 50) { $score = 3; }elseif ($row4['score'] >= 45) { $score = 2; }elseif($row4['score'] >= 40) { $score = 1; }elseif($row4['score'] >= 0 AND $row4['score'] < 40) { $score = 0; }else{ $score = 0; } $grade_point += $score * $row4['course_unit']; } 

I added

  if ( $grade == 'AR' ) { continue; } 

But the calculations are the same. It adds a course_unit value to any course that has

 $grade == 'AR' . 

I will be delighted with your answers. Many thanks.

UPDATE

I can solve part of the piont class by adding

  elseif($row4['score'] >= 0 AND $row4['score'] < 40) { $score = 0; }else{ $score = 0; } 

This sets both scores between 0 and 39 to zero, and the default score <0 (i.e. AR) to zero. But it still sets the value of courses with an AR score of -1 and defaults to the corresponding course_nit values.

I think this problem occurs because cursor_unit is preloaded from the database. Any help?

 Courses Table Stucture ================= course_id course_code course_title course_unit 

I will be very happy for your answers. Thank you pending.

+4
source share
2 answers

Is it as simple as adding "AND NOT 'AR" to a SELECT SUM statement?

Or ... if your DB values ​​come in as AR, why can't you use PHP is_int () in your loop? This will allow you to still assign 0 to F and just skip any non-integer values ​​sent from your database.

+1
source

I will take a hit on you, although it’s hard to find what you are trying to do because of some conflicting statements, such as; "without adding a course rate for a course with a grade of" AR ", and" But it still sets the value of courses with a grade of AR and a grade of -1, default course_unit values.

It seems to me that query3 returns the sum of all course_units excluding grades or points, so instead of adding try subtracting something like:

 if ( $grade == 'AR' ) { // Remove current course_unit from 'Total' derived in query } // Total remains untouched b/c the class was successfully completed 

I hope this makes sense, although the expression you made in your last comment; β€œBut when I run my query on units that are still added to the common units of the course,” it is confusing because query3 blindly calculates the total using 0 logic.

+1
source

Source: https://habr.com/ru/post/1402112/


All Articles