2013-03-31 88 views
0

我面臨的一個問題,笨來獲取數組如何在codeigniter- php中打印對象數組?

$data['one']=$this->db->query($sql1); 
$data['tho']=$this->db->query($sql2); 
$data['three']=$this->db->query($sql3); 

我想如果我做var_dump($data['one']);我正在以下顯示要做到這一點下面的代碼我收到錯誤

Fatal error: Call to a member function result() on a non-object in 

Array 
(
[0] => stdClass Object 
(
    [date] => 2013-09-28 
) 
[1] => stdClass Object 
(
    [date] => 1970-01-01 
) 
[2] => stdClass Object 
(
    [date] => 2013-09-28 
) 
) 

回答

2

你可以(在控制器中)像這樣foreach其中一個數組:

foreach ($data['one']->result() as $row) 
    { 
     echo $row->date; //or whatever the query returns 
    } 

如果你想打印在視圖中,像這樣做:

foreach ($one->result() as $row) 
    { 
     echo $row->date; //or whatever the query returns 
    } 

查看更多有關查詢的官方文檔中here