Hi Chris,

Why are you not able to change that loop, is the loop itself some how
legacy? It's not clear to me where/how the minimum and maxium members
values need to be determined - where does that come from, is that in
the stat table?

Anyway here are a few different permutations depending on what you
need, none of it is tested (obviously) and I doubt any of them will
give you what you want out of the box, but perhaps they might help on
the way.

OLD:
$start = $this->Stat->findAll(
                array(
                        'Site.category' => $category,
                        'Stat.s_date' => $start_date
                        )
                );
$finish = $this->Stat->findAll(
                array(
                        'Site.category' => $category,
                        'Stat.s_date' => $finish_date
                        )
                );

NEW:
$resultsMin = $this->Stat->findAll(
                array(
                        'Site.id' => $siteId,
                        'Stat.s_date' => "BETWEEN $start_date AND $finish_date",
                        ),
                array(
                        'DISTINCT s_date',
                        'members',
                        'threads',
                        'posts',
                        etc.
                        ),
                'Stat.members ASC'
                );

$resultsMax = $this->Stat->findAll(
                array(
                        'Site.id' => $siteId,
                        'Stat.s_date' => "BETWEEN $start_date AND $finish_date",
                        ),
                array(
                        'DISTINCT s_date',
                        'members',
                        'threads',
                        'posts',
                        etc.
                        ),
                'Stat.members DESC'
                );

OR why not get the DB to do it?

$results = $this->Stat->findAll(
                "Site.id = '$siteId' AND Stat.s_date BETWEEN $start_date AND
$finish_date GROUP BY Stat.s_date",
                        ),
                array(
                        'MIN(members) as MinMembers',
                        'MAX(members) as MaxMembers',
                        etc.
                        )
                );

as mentioned by oldgreycells, agreagate functions are not in the
results for any particular model, but that isn't much of a problem if
you use afterFind or otherwise take account of where this data will be.

HTH,

AD7six
Please note:
The manual/bakery is a good place to start any quest for info.
The cake search (at the time of writing) erroneously reports less/no
results for the google group.
The wiki may contain incorrect info - read at your own risk (it's
mainly user submitted) :) 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to