Laravel 4 如何在Laravel中将数据库字段值增加1

Laravel 4 如何在Laravel中将数据库字段值增加1,laravel-4,Laravel 4,我有一张学生出勤表 字段/数据样本 id | studid | cls_id | smonth | syear | total_p | total_a 1 | 20 | 2 | 08 | 2015 | 2 | 1 2 | 21 | 2 | 08 | 2015 | 1 | 0 3 | 22 | 2 | 08 | 2015 | 2 | 1 我想检查上次更新中每个

我有一张学生出勤表

字段/数据样本

id | studid | cls_id | smonth | syear | total_p | total_a
1  |   20   |   2    |   08   | 2015  |   2     |   1
2  |   21   |   2    |   08   | 2015  |   1     |   0
3  |   22   |   2    |   08   | 2015  |   2     |   1
我想检查上次更新中每个学生的
total_p
total_a
值,然后增加1

如果我进入,两个学生都是
present=1
,所以我想要
total\u p值20=3,21=2,22=3

如何获取数据库字段值和增量1

我的控制器

$present = Input::get($student->id);
if ($checkatt)
{
    if ($present == 1)
    {
        DB::table($wys_total_attend_table)->where('studid', $student->id)
            ->where('smonth', $date_exploded[1])
            ->where('syear', $date_exploded[2])
            ->where('stotal_p', 1)
            ->update(array(
                'stotal_p' => 1 + 1,
            ));
        DB::table($wys_total_attend_table)->where('studid', $student->id)
            ->where('smonth', $date_exploded[1])
            ->where('syear', $date_exploded[2])
            ->where('stotal_p', 0)
            ->update(array(
                'stotal_p' => 1,
                'stotal_a' => 0,
            ));
    } elseif ($present == 0)
    {
        DB::table($wys_total_attend_table)->where('studid', $student->id)
            ->where('smonth', $date_exploded[1])
            ->where('syear', $date_exploded[2])
            ->where('stotal_a', 1)
            ->update(array(
                'stotal_a' => 1 + 1,
            ));
        DB::table($wys_total_attend_table)->where('studid', $student->id)
            ->where('smonth', $date_exploded[1])
            ->where('syear', $date_exploded[2])
            ->where('stotal_a', 0)
            ->update(array(
                'stotal_a' => 1,
            ));
        DB::table($wys_total_attend_table)->where('studid', $student->id)
            ->where('smonth', $date_exploded[1])
            ->where('syear', $date_exploded[2])
            ->where('stotal_p', 1)
            ->where('stotal_a', 0)
            ->update(array(
                'stotal_a' => 0 + 1,
            ));
    }
}

我想你只是想更新total_p和total_a列的每一条记录,简单一点:

//get the id of student
$student_id = Input::get('student_id');
$present = Input::get('status'); //dropdown value 0,1
//You need a model for your table let say:
#Student.php
<?php
class Student extends Eloquent{
    protected $table = 'students'; //table name 
}
//Your Controller codes
public function findStudent($id, $status){
$query=Student::find($id);
if($query->count() && $status==1 ){ //status 1 = present
  $query->total_p += 1; //plus one value in the total_p column in the tbl.
  $query->save();
 }else{
  $query->total_a +=1;
  $query->save();
 }
}
//获取学生的id
$student_id=Input::get('student_id');
$present=Input::get('status')//下拉值0,1
//您的桌子需要一个模型,比如:
#Student.php

我想你只是想更新total_p和total_a列的每一条记录,简单一点:

//get the id of student
$student_id = Input::get('student_id');
$present = Input::get('status'); //dropdown value 0,1
//You need a model for your table let say:
#Student.php
<?php
class Student extends Eloquent{
    protected $table = 'students'; //table name 
}
//Your Controller codes
public function findStudent($id, $status){
$query=Student::find($id);
if($query->count() && $status==1 ){ //status 1 = present
  $query->total_p += 1; //plus one value in the total_p column in the tbl.
  $query->save();
 }else{
  $query->total_a +=1;
  $query->save();
 }
}
//获取学生的id
$student_id=Input::get('student_id');
$present=Input::get('status')//下拉值0,1
//您的桌子需要一个模型,比如:
#Student.php

你为什么要检查学生的总数?如果你只想通过增量1更新他们的记录,为什么要检查学生的总人数?如果你只想更新他们的记录增量为1sir,这是行不通的。。。我只想知道如何增加total_p和total_a值。首先选中iam复选框studid=28和total_p value=1,然后选中iam agin复选框studid=28和total_p=2(仅更新了total_p value)我忘记了this$query->total_p+=1$查询->保存();也在else语句$query->total_a+=1中$查询->保存();先生,我不使用模型。。我想检查这个条件DB::table($wys_total_attribute_table)->where('studid',$student->id)->where('smonth',$date_exploded[1])->where('syear',$date_exploded[2])->where('total_p',1)然后增量total_p值变为1。先生,这不起作用。。。我只想知道如何增加total_p和total_a值。首先选中iam复选框studid=28和total_p value=1,然后选中iam agin复选框studid=28和total_p=2(仅更新了total_p value)我忘记了this$query->total_p+=1$查询->保存();也在else语句$query->total_a+=1中$查询->保存();先生,我不使用模型。。我想检查这个条件DB::table($wys_total_attribute_table)->where('studid',$student->id)->where('smonth',$date_exploded[1])->where('syear',$date_exploded[2])->where('total_p',1)然后增量total_p值变为1。