Cakephp:每天随机记录一次
我怎样才能得到24小时后才改变的随机结果Cakephp:每天随机记录一次,cakephp,random,Cakephp,Random,我怎样才能得到24小时后才改变的随机结果 $random = $this->Post->find('first',array( 'conditions' => array( 'Post.active'=>1, ), 'order' => 'rand()', )); $this->view($random['Post']['id']); $this->rend
$random = $this->Post->find('first',array(
'conditions' => array(
'Post.active'=>1,
),
'order' => 'rand()',
));
$this->view($random['Post']['id']);
$this->render('view');
您可以尝试根据当前日期为
rand()
函数使用种子
$random = $this->Post->find('first', array(
'conditions' => array(
'Post.active' => 1,
),
'order' => 'rand(' . date('Ymd') . ')',
));
或者,缓存结果并每天刷新缓存一次。我收到以下错误:'数据库错误:SQLSTATE[42S22]:未找到列:1054 order子句中的未知列“1431993600”:SQL查询:SELECT Item.Item_state_id,Item.title,Item.slug,Item.id,Item.parent_id,Item.presentation,Item.image,Item.image_dir,来自enjoytoscana_01.vnt_items的Item.tag_title作为Item,其中Item.parent_id=63和Item.Item_state_id=1 ORDER BY RAND(1431993600)ASC LIMIT 12注意:如果您想自定义此错误消息,请创建app/View/Errors/pdo_error.ctp'原始帖子中的代码是否有效?例如,
'order'=>'rand()'
有效吗?如果您的原始代码正常工作,我看不出我的代码怎么会失败。您可能需要将rand()
添加到select中,或者只需将其更改为select*