if statement inside array : codeigniter

Posted by ahmad on Stack Overflow See other posts from Stack Overflow or by ahmad
Published on 2010-04-04T05:23:36Z Indexed on 2010/04/04 5:33 UTC
Read the original article Hit count: 190

Filed under:

Hello ,

I have this function to edit all fields that come from the form and its works fine ..

function editRow($tableName,$id)
    {

    $fieldsData = $this->db->field_data($tableName);
    $data = array();
    foreach ($fieldsData as $key => $field)
    {
      $data[ $field->name ] = $this->input->post($field->name);
    }
    $this->db->where('id', $id);
    $this->db->update($tableName, $data);

  }

now I want to add a condition for Password field , if the field is empty keep the old password , I did some thing like that :

function editRow($tableName,$id)
{
    $fieldsData = $this->db->field_data($tableName);
    $data = array();
    foreach ($fieldsData as $key => $field)
    {
        if ($data[ $field->name ] == 'password' && $this->input->post('password') == '' )  
            {
              $data[ 'password' ] => $this->input->post('hide_password'),
              //'password'        => $this->input->post('hide_password'),
            }
            else {
               $data[ $field->name ] => $this->input->post($field->name)
            }
        }
        $this->db->where('id', $id);
        $this->db->update($tableName, $data);
    }

but I get error ( Parse error: syntax error, unexpected T_DOUBLE_ARROW in ... )

Html , some thing like this :

<input type="text"  name="password"  value="">
<input type="hidden"  name="hide_password"  value="$row->$password"  />

umm , any help ?

thanks ..

© Stack Overflow or respective owner

Related posts about codeigniter