You can just build it up from the data you've got:
CONCAT('/course/view.php?id=', co.id, '#section-', cm.section) in SQL or
new moodle_url('/course/view.php', ['id' => $record->id], 'section-' . $record->section); in PHP
You can just build it up from the data you've got:
CONCAT('/course/view.php?id=', co.id, '#section-', cm.section) in SQL or
new moodle_url('/course/view.php', ['id' => $record->id], 'section-' . $record->section); in PHP