2014-11-20 52 views
0

我想獲取從數據庫中的記錄的頁面沒有PARENT_ID,或者我們可以說,網頁沒有父..

頁面模型 .......... ................................

public function get_no_parents() { 
// fecth pages wihtout parents 
$this->db->select ('id','title'); 
$this->db->where ('parent_id', 0); 
$pages = parent::get(); 
// if there are pages then return key as page->id and value $page->title 
$array = array (
0 => 'no parent' 
); 

if(is_array($pages)){ 

foreach ($pages as $page){ 

$array[$page->id]=$page->title; 
    $return $array; 


    } 
    } 
} 

.....頁面控制器

$this->data['pages_no_parents']=$this->Page_model->get_no_parents(); 
    var_dump($this->data['pages_no_parents']); 

.... 轉儲爲空我有兩個錯誤

1未定義的屬性:stdClass的:: $標題

2-無效提供的foreach()參數

有人可以幫助我嗎?

+0

'return $ array;' – Brewal 2014-11-20 16:34:06

+0

仍存在問題 – syedsafir 2014-11-20 16:35:34

+0

仍然存在* a *問題,但您有另一個問題。什麼'parent :: get();'返回? – Brewal 2014-11-20 16:36:36

回答

1

變化:

$this->db->select ('id','title'); 

要:

$this->db->select ('id, title'); 

希望這有助於!

+1

thnks它的工作,你能解釋給我嗎?它們之間有什麼不同? – syedsafir 2014-11-20 18:19:19

+0

'$ this-> db-> select()'只需要2個參數:1)選擇字符串2)一個標誌來顯示字符串是否應該被轉義。所以,當你有'('id','title')時,''id'是唯一被作爲select的一部分傳遞的字符串,如果這有意義的話? – 2014-11-21 11:24:12

相關問題