Did you debug($post)? Cake put the test value under a different array because you used a function. See this for a neat workaround:
http://teknoid.wordpress.com/2008/09/29/dealing-with-calculated-fields-in-cakephps-find/ On Wed, Apr 29, 2009 at 6:51 AM, Danno <daniel.ko...@gmail.com> wrote: > > Can't figure out why i get the undefined index error, when using > "COUNT() AS test" in my query... > > I've tried a whole range of different ways of writing the SQL (cake > format and just straight SQL) > > Seems that the view just doesn't pick up the name given after AS as a > valid field... all other fields that actually occur in the table get > recognised... > > --Controller > $conditions = array('fields' => array('*','COUNT(id) as > test'), 'group' => 'id'); > $posts = ClassRegistry::init('Calendar')->find('all', > $conditions); > $this->set( 'posts', $posts); > > --View > <?php foreach ($posts as $post): ?> > <tr> > <td><?php echo $post['Calendar']['date']; ?></td> > <td><?php echo $post['Calendar']['test']; ?></td> > </tr> > <?php endforeach; ?> > > Hope someone can help... > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---