Skip to content

Instantly share code, notes, and snippets.

@hugodotlau
Created November 7, 2012 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hugodotlau/4031109 to your computer and use it in GitHub Desktop.
Save hugodotlau/4031109 to your computer and use it in GitHub Desktop.
get random values from model use Yii framework
<?php
#ref: http://www.yiiframework.com/forum/index.php/topic/15298-how-can-i-get-random-values-from-model/page__view__findpost__p__76052
$max = Table::model()->count(array(
'condition' => 'status<:status',
'params' => array('status' => Table::STATUS_A)
));
$offset = rand(0,$max);
$object = Table::model()->find(array(
'condition' => 'status<:status',
'params' => array('status' => Table::STATUS_A),
'offset' => $offset,
'limit' => 1
));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment