0

I have a table student attendance.

Fields/data sample

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

I want, to check what is the total_p and total_a value of each students in last update and then increment 1.

If I am enter the both students are present = 1 so I want total_p value 20=3, 21=2, 22=3

How to get database field values and increment 1's.?

My controller

$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,
            ));
    }
}
1
  • Why do you want to check the total_p of student ? if u only want to update their record by increment to 1 Commented Aug 17, 2015 at 14:02

1 Answer 1

2

I think u just want to update each record of total_p and total_a column just make it simple:

//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();
 }
}
Sign up to request clarification or add additional context in comments.

3 Comments

sir ,its not work... I want only how to increment total_p and total_a value? .1st iam checked checkbox studid=28 and total_p value=1 then iam agin check checkbox ,the studid=28 and total_p=2 (only total_p value updated)
i forgot the this $query->total_p += 1; $query->save(); also in else statement $query->total_a += 1; $query->save();
sir ,iam not use model.. i want check this condition DB::table($wys_total_attend_table)->where('studid', $student->id) ->where('smonth', $date_exploded[1]) ->where('syear', $date_exploded[2])->where('total_p',1) then increment total_p value become 1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.