title: accessing result array in codeigniter
body: <p>I have the following happening in my model:</p>
  
  <pre><code>public function load_user_menu($username)
      {
          $this-&gt;db-&gt;select('*');
          $this-&gt;db-&gt;from('menu');
          $this-&gt;db-&gt;where('username', $username);
          $query = $this-&gt;db-&gt;get();
          return $query-&gt;result();
      }
  </code></pre>
  
  <p>and the following in my controller:</p>
  
  <pre><code>public function index()
      {     
          /*If user previously logged in and not logged out, username remains in session.
              load username and load profile data. 
          */
          //check if user logged in or not
          if(($this-&gt;session-&gt;userdata('username')!=""))
          {
              //load data from model
              $profile = array();
              $username = $this-&gt;session-&gt;userdata('username');
              $result = $this-&gt;profileModel-&gt;user_profile($username);
               foreach($result as &amp;$value)
                {
                    $profile['userdetails'] = $value;
                }
              $this-&gt;load-&gt;view('profile', $profile);
          }else{
              //redirect to login function
              $this-&gt;login();
          }
      }
  </code></pre>
  
  <p>but I am getting errors on profile view. I am sure I am accessing them wrong because I am doing this on view:</p>
  
  <pre><code>&lt;? echo $userdetails['profilepic']; ?&gt;
  </code></pre>
  
  <p>and nothing is showing  but this error:</p>
  
  <blockquote>
    <p>A PHP Error was encountered</p>
    
    <p>Severity: Notice</p>
    
    <p>Message: Trying to get property of non-object</p>
    
    <p>Filename: controllers/profile.php</p>
    
    <p>Line Number: 60</p>
  </blockquote>
  
  <p>which am certain because of the wrong accessing. How can I access the details based on the above?</p>