php - Math operation in yii 2 Active Query -
is there way subtract value in int column 1?i have button when clicked call function save data in table want know how subtracting number in database using yii 2 have tried following code below had no effect. can me how make math operations in yii 2?
public static function addsubject($subjectid, $clientid){ $subject = activecurriculum::findone(['subjectid' => $subjectid]); $activesubject = new activesubject(); $activesubject->clientid = $clientid; $activesubject->subjectid = $subject->subjectid; $activesubject->subjectcode = $subject->subjectcode; $activesubject->days = $subject->days; $activesubject->time = $subject->time; $activesubject->section = $subject->section; $activesubject->room = $subject->room; $activesubject->units = $subject->units; $subject->units = $subject->units - 1; //this should subtract number //of slots 1 not working. $activesubject->save(); return true; //return static::findone(['subjectid' => $subjectid]); //->where(['subjectid' => $subjectid]); }
when made changes in ar object , want changes saved should execute ->save()
:
$subject->units = $subject->units - 1; $subject->save();
looks forgot that.
Comments
Post a Comment