Wil*_*son 1 php zend-framework
我正在编写一个涉及选举结果的Zend 1.12应用程序.我可以使用DbTable fetchAll来检索特定骑行中的候选人,但我想通过投票从大多数到最少(DSC)(而不是默认的最少到最多(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
}
Run Code Online (Sandbox Code Playgroud)
这得到骑马的候选人并通过投票命令他们,但在ASC而不是DSC.我尝试用几种不同的方式将'DSC'插入到fetchAll参数中,数据库抱怨它被要求ORDER BY 'votes DSC' ASC.
第一:它DESC,而不是DSC:)只需使用zend函数而不是普通的sql(如注释中所述):
public function fetchForRiding($riding)
{
$select = $this->getDbTable()->select();
$select->where('riding = ?', $riding);
$select->order('votes DESC');
$resultSet = $this->getDbTable()->fetchAll($select);
[...]
return $candidates
}
Run Code Online (Sandbox Code Playgroud)
(另)
| 归档时间: |
|
| 查看次数: |
4169 次 |
| 最近记录: |