After handing out so much help (some good, some bad) I need some help
getting a query to work with the models.
Currently, I have the following two queries using the model:
$start_results = $this->Stat->findAll("Site.category = {$category} AND
Stat.s_date = '{$start_date}'");
$finish_results = $this->Stat->findAll("Site.category = {$category}
AND Stat.s_date = '{$finish_date}'");
Site as a hasMany relationship with Stat
Stat has a belongsTo relationship with Site
Now, what I need to do is change the query to do the following
select min(members) as from stats where site_id =<site_id goes here>
AND (s_date >= '<start_date>' AND s_date <= '<finish_date>');
select max(members) from stats where site_id = <site_id goes here> AND
(s_date >= '<start_date>' AND s_date <= '<finish_date>');
I need to have model-derived results sets so that I don't have to
change any following code:
if (is_array($start_results) && is_array($finish_results)) {
$report_date = "{$start_date} to {$finish_date}";
foreach ($start_results as $result) {
$site_id = $result['Site']['id'];
$site_name[$site_id] = $result['Site']['name'];
$start_members[$site_id] = $result['Stat']['members'];
$start_threads[$site_id] = $result['Stat']['threads'];
$start_posts[$site_id] = $result['Stat']['posts'];
}
foreach ($finish_results as $result) {
$site_id = $result['Site']['id'];
$finish_members[$site_id] = $result['Stat']['members'];
$finish_threads[$site_id] = $result['Stat']['threads'];
$finish_posts[$site_id] = $result['Stat']['posts'];
}
// Figure out the distances in the range
if (is_array($start_members)) {
foreach ($start_members as $site_id => $data) {
$members[$site_id] = $finish_members[$site_id]
- $start_members[$site_id];
$threads[$site_id] = $finish_threads[$site_id]
- $start_threads[$site_id];
$posts[$site_id] = $finish_posts[$site_id] -
$start_posts[$site_id];
}
}
}
Any help would be greatly appreciated.
--
Chris Hartjes
"The greatest inefficiencies come from solving problems you will never have."
-- Rasmus Lerdorf
@TheBallpark - http://www.littlehart.net/attheballpark
@TheKeyboard - http://www.littlehart.net/atthekeyboard
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---