Moodle API question: choose_from_menu and get_records

Re: Moodle API question: choose_from_menu and get_records

by John Papaioannou -
Number of replies: 0
Off the top of my head:

All the get_records family returns an array with items like integer => object. Therefore you won't be able to directly do what you want without some preprocessing.

Example: You want to present a menu of items from table X. Specifically, you want to show the names in a menu and submit the ids as part of a form.

Code:
$results = get_records_select('X', $where_condition, $sort_order, 'id, name');

// Should ALWAYS check that $results is not false right here

foreach($results as $id => $result) {
$results[$id] = $result->name;
}

// NOW you can use choose_from_menu