get record problem doesnt return anything

get record problem doesnt return anything

by Esteban Montes de Oca -
Number of replies: 2

Hi , im trying to use get_record function but, when i tryed the following way doesnt work


$course = $DB->get_records('course',array('idnumber' => $idnumber));


but if I pass the data 

$course = $DB->get_records('course',array('idnumber' =>6417 )); works fine.

Which is the problem?  


Average of ratings: -
In reply to Esteban Montes de Oca

Re: get record problem doesnt return anything

by studyingroup com -
Your code looks right to me.
What do you mean it doesn't work? $course gets no value or does it send an error?
Warning: $DB->get_records doesn't procress string in value (That's a strange limitation... )! Are you sure $idnumber IS a number?
In reply to studyingroup com

Re: get record problem doesnt return anything

by Dominique Palumbo -
Picture of Particularly helpful Moodlers Picture of Plugin developers
Hi,

In the database the field idnumber in the table course is not a number.

$course = $DB->get_records('course',array('idnumber' => MYCOURSE_2021)); // it's worked
you probably need to assign $idnumber like this : $idnumber = '6417';
And use strval() to be sure it's consider as a string if it's come from somewhere else.

Dominique.