user1531800
user1531800

Reputation: 11

Using RAND() in Zend Framework

My client website using Zendframework. Now they ask me to random the result. I using RAND() but not working. Anybody can help?

Here is the code (the RAND() at the bottom)

$oPlaceSelect = $oPlaces->select()->setIntegrityCheck(false)
 ->from(array('p' => 'places'),
 array('id', 'place_title' => 'title', 'alias', 'categories_id',                
 => '(SELECT path FROM places_images WHERE places_images.places_id = p.id group by places_id)'))
->order('RAND()');

Thanks,

Upvotes: 1

Views: 606

Answers (1)

Richard Parnaby-King
Richard Parnaby-King

Reputation: 14882

To use mysql function in a Zend Select object, you need to use 'Zend_Db_Expr'

->order(new Zend_Db_Expr("RAND()"));

Upvotes: 4

Related Questions