2013-08-19 22 views
2

我正在處理codeigniter。我想從後端顯示數據到視圖文件。這裏是我的代碼想要使用索引來顯示數據..?

$result = $obj->get_details(); 

if ($result[0]) 
    { 
      for ($i=0; $i<count($result); $i++) { 

       echo $result [$i]['name']; 
      } 
    } 

雖然我這樣做我收到錯誤「不能使用stdClass類型的對象作爲數組」。我想使用索引來顯示數據。例如我只想顯示數組的第五個索引的名稱。任何幫助將是可怕的...謝謝!

回答

0

嘗試像

for ($i=0; $i<count($result); $i++) { 

    echo $result[$i]->name; 
} 

因爲$result[$i]是將包含name

0

嘗試,而不是這個

echo $result [$i]->name; 

對象

echo $result [$i]['name']; 
相關問題