【问题标题】:Trouble ordering information when pulled from the database in zend.从 zend 中的数据库中提取信息时出现排序问题。
【发布时间】:2012-03-13 19:28:45
【问题描述】:

所以我无法根据数据库中的 id 从数据库订单中获取信息。我根据一本书(Apress 出版的“Pro Zend Framework Techniques”)中的教程编写了以下函数,这本书充满了错别字和错误,所以我希望它只是我忽略的东西。

    public function getRecentArticles ($count = 99, $namespace = 'article')
{
    $select = $this->select();
    $select->order = 'id DESC';
    $select->where('namespace = ?', $namespace);
    $select->limit($count);
    $results = $this->fetchAll($select);
    if ($results->count() > 0) {
        $articles = array();
        foreach ($results as $result) {
            $articles[$result->id] = new Rt_Content_Item_Article($result->id);
        }
        return $articles;
    } else {
        return null;
    }
}

如您所见,我正在尝试根据数据库中的 ID 字段以降序排列文章。任何建议都会很棒。 谢谢。

【问题讨论】:

    标签: php database zend-framework zend-db


    【解决方案1】:
    $select = $this->select ()
        ->order ('id DESC')
        ->where ('namespace = ?', $namespace)
        ->limit ($count);
    

    【讨论】:

    • 感谢您这么快的回复!
    【解决方案2】:

    order 是一个函数,与wherelimit 相同。所以你的订单行应该是:

    $select->order('id DESC');
    

    【讨论】:

      猜你喜欢
      • 2016-12-05
      • 2021-10-13
      • 2019-10-01
      • 2019-09-03
      • 2019-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多