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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -