CodeIgniter Forums
Display Saved Database Answers in Form Issue - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Display Saved Database Answers in Form Issue (/thread-52433.html)

Pages: 1 2


Display Saved Database Answers in Form Issue - El Forum - 06-12-2012

[eluser]dhall[/eluser]
So I went with #3 as it appeared to be the easier option.
If test for rows and set the array just as you showed it.
I am now getting this error:

A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: controllers/profile.php
Line Number: 52 (this is the 'value' line below)

Code:
//set fields
$data['first_name'] = array (
    'name' => 'first_name',
    'id' => 'input_field',
    'value' => set_value('first_name', $results->first_name),
    'type' => 'text'
    );

I get this error on every line where I have a $results->... when the db is blank.


Display Saved Database Answers in Form Issue - El Forum - 06-12-2012

[eluser]dhall[/eluser]
I was able to figure it out.

My Model:
Code:
function get_profile()
  {
    $query = $this->db->where('user_id',$this->session->userdata('user_id'))
                      ->get('u_profile');
    return $query->row_array();
  }

My Controller:
Code:
$results = $this->profile_model->get_profile();
    if (count($results) == 0)
    {
      $results = array(
        'first_name' => '',...


//set fields
   $data['first_name'] = array (
    'name' => 'first_name',
    'id' => 'input_field',
    'maxlength' => '20',
    'value' => set_value('first_name', $results['first_name']),
    'type' => 'text'
    );

Everything else was just as you suggested.
Thanks for all your help!!