affected row

i have problem with sql.

when i update a form, not all textfield i change.

how do I know which one I update textfield when i save??

please help me…

Hi

can you post code on View and Controller files ?

Thanks

i mean, in update

$model->save() can update in database.

but i want to know which field i do update. because not all textfield i’m update in form.

example.

in form i have name, birthday, gender, religion.

but when i update, i just change gender.

in controller, $model->save() can handle update action.

but i want to know which field i do update.

sorry for my english, because my english is not so good.

Hi

based on your code need to check your Model file.

if in your model listed same as " name, birthday, gender, religion " than you have to post all data like

$_POST[‘name’]

$_POST[‘birthday’]

$_POST[‘gender’]

$_POST[‘religion’]

than you $model->save(); working with all field otherwise what are match those change not all.

Thanks

When you use Gii to generate your CRUD, you find this perfect standard action in your controller:


<?php

class SampleController extends Controller

{

    ...

    /**

     * Updates a particular model.

     * If update is successful, the browser will be redirected to the 'view' page.

     * @param integer $id the ID of the model to be updated

     */

    public function actionUpdate($id)

    {

        $model=$this->loadModel($id);


        // Uncomment the following line if AJAX validation is needed

        // $this->performAjaxValidation($model);


        if(isset($_POST['Sample']))

        {

            $model->attributes=$_POST['Sample'];

            if($model->save())

                $this->redirect(array('view','id'=>$model->id));

        }


        $this->render('update',array(

            'model'=>$model,

        ));

    }

    ...

}

The current implementation of Active Record doesn’t preserve the loaded attribute values when they have got edited.

So you can not tell what attributes(fields) have been edited in actionUpdate in an ordinary way.

You have to do something like this:




<?php

class SampleController extends Controller

{

    public function actionUpdate($id)

    {

        $model=$this->loadModel($id);

        if(isset($_POST['Sample']))

        {

            $model_org = new Model();  // model instance to save the original values

            $model_org->attributes = $model->attributes;  // save the original values;

            $model->attributes=$_POST['Sample'];  // load the edited values

            $attr1_changed = $model_org->attr1 != $model->attr1;  // compare 2 values

            $attr2_changed = $model_org->attr2 != $model->attr2;

            ...

            if($model->save())

                $this->redirect(array('view','id'=>$model->id));

        }


        $this->render('update',array(

            'model'=>$model,

        ));

    }

}