Welcome Guest, Not a member yet? Register   Sign In
update database with different id
#1

how to do update() deleted_at with different id, i tried it and its not working as it should

Controller Example
    public function RestoreData($id_user)
    {
        $dataUser = [
            'deleted_at' =>  NULL,
        ];
        $this->UserModel->update($id_user, $dataUser);
   
        $dataLogin = [
            'deleted_at' =>  NULL,
        ];
        $this->LoginModel->update($id_user, $dataLogin);
   
        session()->setFlashdata('restore', 'Complete');
        return redirect()->to('Restore');
    }

Database Example
tbl_user
id_user=999 (primary)
deleted_at=2023-07-23 20:31:46

tbl_login
id_login=1 (primary)
id_user=999
deleted_at=2023-07-23 20:31:46

Running Example
/RestoreData/$id_user
($id_user=999)

If I change tbl_login primary_key to id_user it works.

I tried the SQL Query Everything Runs Normal, So How Can the update() Function Update With a Different ID (Not Primary)
Reply
#2

It is ok. The primary key is needed for the update. In this case, you need to make an additional request to get "select ... id_login where id_user = ?" or pass id_login directly to the method
third option is to use the builder to create a query

PHP Code:
$loginModel->set('deleted_at'null)->where('id_user'$id_user)->update() 
Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply
#3

(07-24-2023, 02:56 AM)ozornick Wrote: It is ok. The primary key is needed for the update. In this case, you need to make an additional request to get "select ... id_login where id_user = ?" or pass id_login directly to the method
third option is to use the builder to create a query

PHP Code:
$loginModel->set('deleted_at'null)->where('id_user'$id_user)->update() 

this is working, thanks for the help.  Big Grin
Reply




Theme © iAndrew 2016 - Forum software by © MyBB