if语句内部的语句:codeigniter

时间:2010-04-04 05:23:36

标签: codeigniter

我有这个功能来编辑来自表单的所有字段 它的工作正常..

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);

  }

现在我想为Password字段添加一个条件,如果该字段为空则保留旧密码 ,我做了一些这样的事情:

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);
    }

但是我收到错误(解析错误:语法错误,意外的T_DOUBLE_ARROW ...)

Html ,有点像这样:

<input type="text"  name="password"  value="">
<input type="hidden"  name="hide_password"  value="$row->$password"  />
嗯,嗯,有什么帮助?

谢谢..

2 个答案:

答案 0 :(得分:2)

我不认为“=&gt;”是一个有效的PHP运算符。也许你打算在那条线上使用赋值运算符“=”?

答案 1 :(得分:1)

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);
            }