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
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---