Just yesturday I was wantiong a good solution to this same type of situation. Not wanting to filter / order etc in my views I quickly whipped up a small find funtcion implemented in my app_model.
I'm sure there is possiobly a better implementation of this, but for now it is what it is. I figured the grouping in most of my cases was pretty simple, so for now this will do the trick, keeping my grouping logic out of my views / controllers. http://dark-code.bulix.org/9ofr62-54251 This would in your case return results like this: Array( [Print] => Array( [0] => Array( [Work] => Array( [id] => 1 [name] => piece of work 1 [type] => Print [date] => 2006-03-02 [description] => blah blah [content] => <marquee>WORK!</marquee> ) ) [1] => Array( [Work] => Array( [id] => 2 [name] => piece of work 2 [type] => Print [date] => 2006-03-02 [description] => blah blah [content] => <marquee>WORK!</marquee> ) ) ) [Digital] => Array( [0] => Array( [Work] => Array( [id] => 3 [name] => piece of work 3 [type] => Digital [date] => 2006-03-02 [description] => blah blah [content] => <marquee>WORK!</marquee> ) ) [1] => Array( [Work] => Array( [id] => 4 [name] => piece of work 4 [type] => Digital [date] => 2006-03-02 [description] => blah blah [content] => <marquee>WORK!</marquee> ) ) ) ) Hope that's of some help. Paul. -----Original Message----- From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Geoff Ford Sent: Saturday, 1 September 2007 11:53 p.m. To: Cake PHP Subject: Re: outputting results from a db in groups of common content Use an order by of "type, name" as the third option in the findAll() Then in your view you can do something like $current = ""; foreach ($work in $works){ if ($work['Work']['type'] != $current) { // print heading } // print name and other details } Geoff -- http://lemoncake.wordpress.com On Sep 1, 10:10 am, GunitMail <[EMAIL PROTECTED]> wrote: > Hello! > > Ok here is how an entry in my database looks like: > [Work] => Array > ( > [id] => 1 > [name] => piece of work 1 > [type] => Print > [date] => 2006-03-02 > [description] => blah blah > [content] => <marquee>WORK!</marquee> > ) > > How would I go about getting cakePHP to output these on a page like: > > <h2>Print</h2> > + piece of work 1 > + piece of work 2 > + piece of work 4 > + piece of work 6 > > <h2>Digital</h2> > + piece of work 3 > + piece of work 5 > > So they are grouped together with other entries that share the same > value of a field. > I'm not bothered about fancy db stuff, just some foreach and array > action will make me happy. > > Thanks very much in advance, my PHP has become horribly rusty and dusty __________ NOD32 2497 (20070901) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
