I am trying to get a random ID from a table with a specific visiblity=2
clause but I am having issues getting it to return the ID, it says Undefined index: id
.
$space = Yii::app()->db->createCommand()
->select('id')
->from('space')
->where('id=rand() AND visibility=2')
->limit(1)
->queryAll();
//->queryRow();
echo $space['id'];
Is his not the correct way?
I figured out another solution using the already loaded info from my original version without guest check.
$max = Space::model()->count();
$randId = rand(0,$max);
$space = Space::model()->find(array('offset'=>$randId));
if ($space->attributes['visibility'] == 2) {