I have a table total_count
+----+--------+-------+------+---------+---------+---------+
| id | studid | month | year | acls_id | total_p | total_a |
+----+--------+-------+------+---------+---------+---------+
| 1 | 30 | 08 | 2015 | 12 | 5 | 2 |
| 2 | 35 | 08 | 2015 | 12 | 5 | 2 |
| 3 | 52 | 08 | 2015 | 12 | 5 | 2 |
| 4 | 53 | 08 | 2015 | 12 | 5 | 2 |
| 5 | 54 | 08 | 2015 | 12 | 5 | 2 |
| 6 | 55 | 08 | 2015 | 12 | 5 | 2 |
| 7 | 30 | 09 | 2015 | 12 | 3 | 0 |
| 8 | 35 | 09 | 2015 | 12 | 3 | 0 |
| 9 | 52 | 09 | 2015 | 12 | 2 | 1 |
| 10 | 53 | 09 | 2015 | 12 | 3 | 0 |
| 11 | 54 | 09 | 2015 | 12 | 3 | 0 |
| 12 | 55 | 09 | 2015 | 12 | 3 | 0 |
+----+--------+-------+------+---------+---------+---------+
I want to increment and decrement for each student total_p and total_a.
when iam edit my student attendance list.
eg:studid 30 total_p = 5 and total_a= 2 ,so iam edit my attendance present become absent .
so want decrement total_p by 1 and increment total_a by 1.
So I'd like to get the total of each month for each studid and a increment and decrement of total_p and total_a for the total months.
My controller code is
if ($present ==0) {
DB::table($wys_total_attend_table)->where('studid',$student->id)
->where('smonth','=',$date_exploded[1])
->where('syear','=',$date_exploded[2])
->increment('stotal_a', 1)
->decrement('stotal_p',1);
}
elseif ($present ==1) {
DB::table($wys_total_attend_table)->where('studid',$student->id)
->where('smonth','=',$date_exploded[1])
->where('syear','=',$date_exploded[2])
->increment('stotal_p', 1)
->decrement('stotal_a', 1);
}
but it doesn't work..
How to use increment() and decrement() in query builder format?
for eg:if iam only edit studid =30 attendance increment total_p value 1 and (present==1) studid =30 total_p=6 and total_a=1 and other studid values are old value.
laravel php laravel 5 laravel 4 laravel with laravel tutorial
Aucun commentaire:
Enregistrer un commentaire