Perfect. Thanks! On Feb 8, 7:11 am, "AD7six" <[EMAIL PROTECTED]> wrote: > On Feb 8, 7:49 am, "Dan Bair" <[EMAIL PROTECTED]> wrote: > > > > > Hello Bakers, > > > Currently I have a table that holds the favorite films of users > > (fn_favorites). In each row in this table, it holds the film's id > > (film_id) and the user's id (user_id). I am making a list of the > > "User's Top Favorites" which takes the films that occur this most in > > this table. Right now, I have to do a SQL query to get these id's that > > occur the most, and then put them in an array, and then do a findAll > > with those ids to get the film's information. > > > I was wondering if anyone could point me to a cleaner way to > > accomplish this? The real thing that made me go this direction was > > that I could not find a way to count occurances of a value in a column > > and then order them. > > > Here is the code I currently have: > > > // grabs the 3 ids that occur the most > > $fav = $this->Favorite->query( > > 'SELECT film_id, COUNT(film_id) FROM fn_favorites > > GROUP BY film_id > > ORDER BY COUNT(film_id) DESC > > LIMIT 3'); > > // assign id's into an array > > $fav = array( $fav[0]['fn_favorites']['film_id'], > > > > $fav[1]['fn_favorites']['film_id'], > > > > $fav[2]['fn_favorites']['film_id']); > > //grab film information on the 3 top favorites > > $fav = $this->Film->findAll( array("Film.id" => $fav ) ); > > $this->set( 'fav', $fav ); > > > Thanks in advance! > > ~ Dan > > http://groups.google.com/group/cake-php/search?group=cake-php&q=%22GR...http://groups.google.com/group/cake-php/search?group=cake-php&q=%22fi... > > HTH, > > AD7six > Please note: > The manual/bakery is a good place to start any quest for info. > You may get your answer quicker by asking on > the IRC Channel (you can access it with just a browser > here:http://irc.cakephp.org).
--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---