CodeIgniter Forums
Display db data in edit profile page - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Display db data in edit profile page (/showthread.php?tid=52259)



Display db data in edit profile page - El Forum - 06-03-2012

[eluser]Ignis Avis[/eluser]
I want to display existing data in the fields when i will go to edit page.

Here is my model function.
Code:
public function edit_user($member_id)
{
   $this->db->select('fullname','country','district','address','nominee_name','nominee_relation','mobile_no','password','bank_acc_no','bank_acc_name','bank_name','branch_name');
   $this->db->limit('1');
   return $this->db->get_where('user', array('member_id'=> $member_id))->row();
}

Here is the controller function.
Code:
function edit_profile()
{
  $data['title']= 'Edit Profile';
  $member_id = $this->session->userdata('member_id');
  $this->load->model('user_model','',TRUE);
  $data['row'] = $this->user_model->edit_user($member_id);
        $this->load->view('edit_profile.php', $this->data);
}

and in my view file for a sing field I am using this.
Code:
<input type="text" value="<?php echo $row['full_name'];?>"/>

But I am getting following error.
Code:
Severity: Notice

Message: Undefined variable: row

Filename: views/edit_profile.php
I am new in codeigniter and can't figure out why this is happening.


Display db data in edit profile page - El Forum - 06-03-2012

[eluser]Glazz[/eluser]
Instead of
Code:
$this->load->view('edit_profile.php', $this->data);

Use:
Code:
$this->load->view('edit_profile.php', $data);




Display db data in edit profile page - El Forum - 06-03-2012

[eluser]Ignis Avis[/eluser]
I am using $this->data to load my template data which have been declared earlier.

I am having problem with the variable row in view file. view is not recognizing that. what should i do to solve that issue?


Display db data in edit profile page - El Forum - 06-03-2012

[eluser]Glazz[/eluser]
If you need to have $this->data passed, you need to merge the $data, something like this:

Code:
$this->load->view('edit_profile.php', array_merge($this->data, $data) );