Tim's advice is good - The output from the debugging info is key.
That said, can I just check that you're intentionally matching 'idnumber', and you're not mistaking it for 'id' (as a number)?
This might be the correct format if so:
$idnumber = 6417; // Should give this a different name to save confusion $course = $DB->get_records('course',array('id' =>$idnumber));
Using 'idnumber' would typically be a string value which you assign in the course settings:
$idnumber = "2021_maths"; $course = $DB->get_records('course',array('idnumber' =>$idnumber));
It's also worth checking what is stored in your $idnumber variable with var_dump($var)/echo/print.
Hope this helps