Displaying the results of get_records_select()

Displaying the results of get_records_select()

by Tim Redman -
Number of replies: 3
Hi,

Having succesfully used get_records_select() to retrieve data from the database I'm having a bit of trouble displaying it. I'm hoping to display values from each record in a table format such that you have
Personla Learning Record



Id
Date
Title
Type
1 (pk of table)
Value from Record
Value from Record
Value From Record
2
Value from RecordValue from RecordValue from Record
2
Value from RecordValue from RecordValue from Record





My question is, is there a function in moodle to do this or somethign similar? I imagine there isnt. But I did see the online users block used print_side_block which does print out a list from the get_records_select() array so i thought id ask! 

If there isnt a function perhaps someone can anyone point me in the direction of a good php tutorial for printing out values from an array of objects to a table so I can write my own function that would be great!

Thanks
Tim
Average of ratings: -
In reply to Tim Redman

Re: Displaying the results of get_records_select()

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
So you've done:

$records = get_records_select('tablename', 'some select criteria');

To just see what you have (as a developer) try this:

print_object($records);

To do something useful with this array of objects you can do:


if ($records) {
echo '
'.$record->id.''.userdate($record->date).''.$record->title.''.$record->type.'
';
}
Average of ratings: Useful (1)
In reply to Martin Dougiamas

Re: Displaying the results of get_records_select()

by Tim Redman -
Martin thankyou!

That bottom piece of code is exactly what i was trying to do.
What you've done in 12 lines of code i failed to do in 30 odd lines and many hours of head scratching this morning!



In reply to Tim Redman

Re: Displaying the results of get_records_select()

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
No worries. To get more fancy use the print_table() function (in /lib/weblib.php)
Average of ratings: Useful (1)