2012-03-13 63 views
0

因此,我無法根據數據庫中的ID從數據庫中獲取信息。我基於一本書中的教程編寫了以下函數(Apress出版的'Pro Zend Framework Techniques'),書中充斥着拼寫錯誤和錯誤,所以我希望它是我可以忽略的東西。在zend中從數據庫中提取時遇到故障排序信息。

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字段順序的文章。任何建議都會很棒。 謝謝。

回答

0

order是一個函數,同樣wherelimit。所以你的訂單行應該是:

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

這解釋了這個問題。非常感謝它! – Cpage 2012-03-13 20:07:24

3
$select = $this->select() 
    ->order ('id DESC') 
    ->where ('namespace = ?', $namespace) 
    ->limit ($count); 
+0

感謝這麼快的回覆! – Cpage 2012-03-13 20:06:46