/**
* Link countries stats
*/
$link_countries = $this->Stat->find('all', array(
'conditions' => array('Stat.link_id' => $id),
'fields' => array('Stat.country', 'COUNT(Stat.country) AS country_num'),
'order' => array(
'country_num' => 'desc'
),
'group' => array('Stat.country'),
));
$countries = Hash::combine($link_countries, '{n}.Stat.country', '{n}.0.country_num');
$this->set('countries', $countries);
/**
* Link continents stats
*/
$link_continents = $this->Stat->find('all', array(
'conditions' => array('Stat.link_id' => $id),
'fields' => array('Stat.continent', 'COUNT(Stat.continent) AS continent_num'),
'order' => array(
'continent_num' => 'desc'
),
'group' => array('Stat.continent'),
));
$continents = Hash::combine($link_continents, '{n}.Stat.continent', '{n}.0.continent_num');
$this->set('continents', $continents);
喜欢这个
/**
* Link stats for last 30 days
*/
$linksStats = $this->Stat->find('all', array(
'conditions' => array(
'Stat.link_id' => $id,
'Stat.created BETWEEN (NOW() - INTERVAL 30 DAY) AND NOW()'
),
'fields' => array('DATE_FORMAT(Stat.created,"%d-%m-%Y") AS statDate', 'COUNT(DATE_FORMAT(Stat.created,"%d-%m-%Y")) AS statDateCount'),
'order' => array(
'Stat.created' => 'DESC'
),
'group' => array('statDate'),
));
$linksStats = Hash::combine($linksStats, '{n}.0.statDate', '{n}.0.statDateCount');
$this->set('linksStats', $linksStats);
在这段代码中他们是30天的间隔,但我想在链接国家/地区统计数据和链接大陆统计数据
中设置24小时内部空间有没有人可以帮助我?
答案 0 :(得分:0)
您可以使用INTERVAL 24 HOUR
代替INTERVAL 30 DAY
。 More Details
$linksStats = $this->Stat->find('all', array(
'conditions' => array(
'Stat.link_id' => $id,
'Stat.created BETWEEN (NOW() - INTERVAL 24 HOUR) AND NOW()'
),
'fields' => array('DATE_FORMAT(Stat.created,"%d-%m-%Y") AS statDate', 'COUNT(DATE_FORMAT(Stat.created,"%d-%m-%Y")) AS statDateCount'),
'order' => array(
'Stat.created' => 'DESC'
),
'group' => array('statDate'),
));