2010-04-04 7 views
0

J'ai cette fonction pour modifier tous les champs qui viennent de la forme et ses belles œuvres ..instruction if intérieur tableau: 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); 

    } 

maintenant je veux ajouter une condition pour le champ Mot de passe, si le champ est vide garder l'ancien mot de passe , je l'ai fait quelque chose comme ça:

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

mais j'obtiens l'erreur (Parse error: syntax error, T_DOUBLE_ARROW inattendue ...)

Html, quelque chose comme ceci:

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

umm, toute aide?

merci ..

Répondre

2

Je ne pense pas "=>" est un opérateur de PHP valide. Peut-être que vous vouliez utiliser "=", l'opérateur d'affectation, sur cette ligne?

+0

Waw ..vous avez raison, merci son travail maintenant :) comment j'ai raté ça !! – ahmad

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