Codeigniter, Displaying results from database -


i new ci, i've been working on hours no success, please help! trying generate user profiles retrieving information database , displaying in view (using userid). getting both undefined variable error , trying property out of non-object error. here code:

model:

 public function my_data() {   $userid = $this->session->userdata('userid');    $data = array();   $this->db->select('*');   $this->db->from('user_profile');   $this->db->where('userid', $userid);   $query = $this->db->get();    return $query->result();   } 

controller:

    public function profile() {           $data['query'] = $this->user_model->my_data();             $this->load->view('header_loggedin');         $this->load->view('sidebar_left');         $this->load->view('user/user_profile', $user);         $this->load->view('footer'); } 

view:

<div class="control-group">  <i class="icon-user"></i>             name: <?php echo $row->name; ?>      </div>     <div class="control-group">  <i class="icon-home"></i>             location: <?php echo $data->location;?>  </div>         <div class="control-group">  <i class="icon-briefcase"></i>             occupation: <?php echo $data->occupation;?>  </div> 

thanks in advance, feel have tried everything!

hi new ci face problems later enjoy here simple stuff doing wrong

model

public function my_data() {   $userid = $this->session->userdata('userid');    $data = array();   $this->db->select('*');   $this->db->from('user_profile');   $this->db->where('userid', $userid);   $query = $this->db->get();    //this return multiple rows or object of arrays   //return $query->result();   // need send single row     return $query->row();   } 

controller

public function profile() {          // in data array key name should same pass view              $data['row'] = $this->user_model->my_data();             $this->load->view('header_loggedin');         $this->load->view('sidebar_left');         $this->load->view('user/user_profile', $data);         $this->load->view('footer'); } 

view

<div class="control-group">  <i class="icon-user"></i>             name: <?php echo $row->name; ?>      </div>     <div class="control-group">  <i class="icon-home"></i>             location: <?php echo $row->location;?>  </div>         <div class="control-group">  <i class="icon-briefcase"></i>             occupation: <?php echo $row->occupation;?>  </div> 

for more information please read ci user guide understand many stuff there ci user guide


Comments

Popular posts from this blog

Winapi c++: DialogBox hangs when breaking a loop -

vb.net - Font adding using PDFsharp -

javascript - jQuery iScroll clickable list elements while retaining scroll? -