Welcome Guest, Not a member yet? Register   Sign In
Display Saved Database Answers in Form Issue
#11

[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.
#12

[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!!




Theme © iAndrew 2016 - Forum software by © MyBB