Friday, July 27, 2012

Select random data from table in yiiframework

To random data some times we need it using logic of programming using variable but now I want to give you another short way to select random data from spesific table
Here some codes that you can try

$models=User::model()->findAll(array(
 'select'=>'*, rand() as rand',
 'limit'=>24,
 'order'=>'rand',
 )
);

From above code we can see that we fetch the table user using criteria. This codes give you a way to select all data with random position of order.

You can try that..

1 comment: