Welcome Guest, Not a member yet? Register   Sign In
Update using WHERE
#14

This code worked.
Result: UPDATE `test` SET `activity_id` = NULL WHERE `activity_id` = 100

Model:
PHP Code:
<?php
namespace App\Models;
use 
CodeIgniter\Model;

class 
TestModel extends Model
{
    protected $table         'test';
    protected $allowedFields = ['activity_id'];

    public function set_activity_id_null($activity_id false)
    {
        if ($activity_id !== false) {
            $this->where('activity_id'$activity_id)
                ->set('activity_id'null)
                ->update();

            return true;
        }

        return false;
    }


Controller:
PHP Code:
<?php
namespace App\Controllers;

class 
Home extends BaseController
{
    public function index()
    {
        $model = new \App\Models\TestModel();
        $model->set_activity_id_null(100);
        echo $model->getLastQuery();
    }

Reply


Messages In This Thread
Update using WHERE - by sevmusic - 01-11-2022, 01:37 PM
RE: Update using WHERE - by BilltheCat - 01-11-2022, 01:43 PM
RE: Update using WHERE - by sevmusic - 01-11-2022, 02:13 PM
RE: Update using WHERE - by iRedds - 01-11-2022, 02:47 PM
RE: Update using WHERE - by sevmusic - 01-11-2022, 03:47 PM
RE: Update using WHERE - by BilltheCat - 01-11-2022, 08:06 PM
RE: Update using WHERE - by sevmusic - 01-14-2022, 07:52 AM
RE: Update using WHERE - by kenjis - 01-14-2022, 05:09 PM
RE: Update using WHERE - by sevmusic - 01-20-2022, 08:02 AM
RE: Update using WHERE - by BilltheCat - 01-20-2022, 08:38 AM
RE: Update using WHERE - by sevmusic - 01-20-2022, 01:20 PM
RE: Update using WHERE - by demyr - 01-20-2022, 11:53 AM
RE: Update using WHERE - by demyr - 01-20-2022, 02:10 PM
RE: Update using WHERE - by kenjis - 01-20-2022, 06:36 PM



Theme © iAndrew 2016 - Forum software by © MyBB