Search code examples
codeignitercodeigniter-2

codeignite trying to get property of non-object not resolved


I am attempting to access the result set from a model query in the view. I have the following:

Controller:

           $courseId = $this->session->userdata('courseId');
            //echo "Course: ".$courseId;
            if(isset($courseId) && $courseId != '')
            {           
                $result = $this->Course_model->loadBasicDetailsEdit($courseId);
                $data['basicCourseDetails'] = $result;
                $this->load->view('course/basicDetails', $data);
            }

Model:

function loadBasicDetailsEdit($courseId)
    {
        $this->db->select('*');
        $this->db->where('course_id', $courseId);    
        $this->db->from('course');
        $query = $this->db->get();
        if ( $query->num_rows() > 0 ) 
        { 
          return $query->result(); 
        } else { 
            return FALSE;   
        }   
    }

and in the view I tried to print_r() and got this:

Array ( [0] => stdClass Object ( [course_id] => 8 [title] => Photography [summary] => [description] => [price] => [member_id] => 12 [category] => [audience] => [goals] => [date] => 2013-09-26 [production] => 0 ) ) 

I tried to access this using $basicCourseDetails->title or $basicCourseDetails['title'] but neither are working. Any hint as to why this is happening?

Regards,


Solution

  • try this:

    foreach($basicCourseDetails as $basic){
        echo($basic->title);
    }
    

    or something like this:

    echo($basicCourseDetails[0]->title);