syedsafir
syedsafir

Reputation: 62

Undefined property: stdClass::$title

i want to fetch the record from database which pages without parent_id or we can say pages without parent..

the page model ..........................................

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;


    }
  }
}

.....the page controller

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

.... the dump is null i have two error

1- Undefined property: stdClass::$title

2- Invalid argument supplied for foreach()

can someone help me ?

Upvotes: 2

Views: 3612

Answers (1)

Rwd
Rwd

Reputation: 35180

Change:

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

To:

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

Hope this helps!

Upvotes: 1

Related Questions