0

I am using MOODLE LMS. Users grade will be stored in the database. Now for example if the users grade is between 1 to 10 then the point 5 should print. But I'm not getting the output. Below is the code

$check1 = $DB->get_record_sql("SELECT grade FROM `mdl_quiz_grades` WHERE userid = $USER->id and quiz = '27';");
            if ($check1 >= 1 && $check1 <= 10){
                $printpoint = 5;
            } else {
                $printpoint = 0;
            }

1 Answers1

0

$check1 doesn't contain the grade value, it contains an object with a single value called "grade" which contains the value you want.

So, either look at $check1->grade or use $DB->get_field('quiz_grades', 'grade', ['userid' => $USER->id, 'quiz' => 27]); to just get the grade value on its own.

davosmith
  • 6,037
  • 2
  • 14
  • 23