NotORM's alternative to dibi's fetchAssoc()

Skip to first unread message

Ondřej Slámečka

Sep 5, 2011, 12:41:25 PM9/5/11

I've got a simple timetable - a set of events. Every event has set its hour and day (and at one time there can be more events). Now I am trying to print them out in a table: With dibi I used to use fetchAssoc('day,hour') (or similar) to get array like this:

  '1' /* day */ => array( 
     '1' /* hour */ => array( array(...) /* event */, array(...) /* event */ ),
     '2' /* hour */ => array( array(...) /* event */ )
I want to get the same array structure with NotORM, but it doesn't have fetchAssoc() method. Is it possible to get array (or traverse database entries) like this or do I have to write my own solution? Or should I try to solve this problem in a completly different way?

I was suggested to rebuild my database structure, but only thing I was able to came with was making own table for days (7 rows) and for hours (7*24 rows) and then selecting days, join hours, join events; although it actually makes sense, it isn't satisfying - imagine extending the application's time scope to year instead of a week…

Thank you

PS: I'm actually using Nette\Database, but I guess there won't be much difference. Here's my original post on Nette forum

Jakub Vrána

Sep 5, 2011, 5:00:13 PM9/5/11
You can use this:

$events = array();
foreach ($db->event() as $event) {
$events[$event['day']][$event['hour']][] = $event;

Jakub Vrana

Ondřej Slámečka

Sep 7, 2011, 2:14:45 PM9/7/11
Ok, as usually nice solution :-) Thank you.
Reply all
Reply to author
0 new messages