NotORM's alternative to dibi's fetchAssoc()

250 views
Skip to first unread message

Ondřej Slámečka

unread,
Sep 5, 2011, 12:41:25 PM9/5/11
to not...@googlegroups.com
Hello,

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:

<?php
array(
  '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 http://forum.nette.org/en/911-nette-database-equivalent-to-dibi-s-fetchassoc

Jakub Vrána

unread,
Sep 5, 2011, 5:00:13 PM9/5/11
to not...@googlegroups.com
You can use this:

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

Jakub Vrana

Ondřej Slámečka

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