views:

77

answers:

2

I'm using Zend framework and trying to get the results to be in a random order. This returns the results but doesn't seem to vary the order. Any ideas?

    class Model_DBTable_Tblquotes extends Zend_Db_Table
{
public function getQuotes()
 { 
  $select = $this->select();  
        $select->setIntegrityCheck(false) 
               ->from('tblQuotes',array('id','quote','author','dateCreated')) 
      ->order(new Zend_Db_Expr('RAND()'))
      ->limit(25, 0);

        return $this->fetchAll($select);

 }
}
+1  A: 

Have you tried

 ->order('RAND()')

instead of

 ->order(new Zend_Db_Expr('RAND()'))

You can also use

 $select->__toString();

On your db obj to get a string of the query so you could echo it and look at it to see whats wrong.

Iznogood
Turned out my original code was working fine. I did however have a caching problem with windows 7 and my version of filezilla - how annoying!! :) Mark you as the answer as your answer was potentially useful
Andi
A: 

you need to pass in the expression as a string: "RANDOM()"

example: ->order(new Zend_Db_Expr('RANDOM()'));

Khaled