Reputation: 338
I'm writing a Zend 1.12 application involving election results. I can use the DbTable fetchAll to retrieve only candidates in a specific riding, but I'd like to order them by vote from most to least (DSC) (instead of the default least to most (ASC)).
//class Application_Model_CandidateMapper
public function fetchForRiding($riding)
{
$where = 'riding = %s';
$resultSet = $this->getDbTable()->fetchAll(sprintf($where, $riding), 'votes');
//blah blah blah
return $candidates
}
This gets the candidates for the riding and orders them by vote, but in ASC instead of DSC. I tried to jack 'DSC' into the fetchAll arguments a few different ways and the database complained it was being asked to ORDER BY 'votes DSC' ASC
.
Upvotes: 1
Views: 4522
Reputation: 1200
First: its DESC
, not DSC
:) Simply use zend functions instead of plain sql (as mentioned in the comment):
public function fetchForRiding($riding)
{
$select = $this->getDbTable()->select();
$select->where('riding = ?', $riding);
$select->order('votes DESC');
$resultSet = $this->getDbTable()->fetchAll($select);
[...]
return $candidates
}
(untested)
Upvotes: 5