2013-09-23 193 views
0

我有一個數據庫,其中包含許多人購買的產品的詳細信息。就像購物車一樣。因此,我必須根據購買日期顯示購買產品的所有人員的詳細信息。我在數據庫中有一個order_date字段。我想知道按排序順序顯示數據的查詢。請幫助我。從數據庫中提取數據並對其進行分類並顯示它

public function get_orders{ 
    return $this->find('all',array('order'=>array('Order.order_date DESC'))); 
} 

這是我的名爲Order的模型。在控制器我打電話使用

$order=$this->Order->get_orders(); 

,並顯示該功能使用每個循環

+0

我的訂單通過查詢不起作用。這裏是我的查詢 – user1991

+0

array('order'=> array('Article.created DESC'))) – user1991

+0

嘗試像這樣'array('order'=> array('Article.created'=>'DESC'))) ;' –

回答

0

讓我們說你的名字Product的模型,然後在你的控制器把這個代碼來獲取降序排列的產品。

$this->Product->find('all', array(
    'order' => array('Product.order_date' => 'DESC') 
)); 

更新:

public function get_orders{ 
    return $this->find('all',array('order'=>array('Order.order_date' => 'DESC'))); 
} 

(OR)

public function get_orders{ 
     return $this->find('all',array('order'=> 'Order.order_date DESC'))); 
} 

對於您可以檢查here更多信息。

+0

對不起,這是行不通的 – user1991

+0

你可以把你的代碼,以便我可以檢查@ user1991 –

+0

public function get_orders {return $ this-> find('all',array('order'=> array('Order.order_date DESC'))); }這是我的名爲Order的模型。在控制器中,我使用$ order = $ this-> Order-> get_orders();來調用這個函數。並顯示使用每個循環 – user1991

相關問題