I am try to append my data array in if conditions. I am using array_push
function to do it Its first time I am using this function for appending array. I am using conditions so that if user has added the value in the form it would update the field otherwise It would not effect the field. The problem is its not updating the database and its unable to set the fields as it shows Unknown Unknown column '0' in 'field list'
$fid = 2;
$password = "test_pass";
$title = "new title of folder";
$f_access = 1;
$newName = TRUE;
$data = array(
'name' => $title,
'access_type' => $f_access
);
if($newName)
{
$data2 = "'icon' => $newName";
array_push($data, $data2);
}
if($password)
{
$data3 = "'password' => $password";
array_push($data, $data3);
}
$this->db->where('id', $fid);
$this->db->update('folders', $data);
array_merge
to preserve precedent indexes