- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一张表 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 |
+----+--------+-------+------+---------+---------+---------+
我想为每个学生 total_p
和 total_a
递增和递减。
当我编辑我的学生出勤列表时。
eg: studid 30 total_p = 5 and total_a= 2 ,so iam edit my attendance present become absent .
所以要将 total_p 减 1,将 total_a 加 1。
所以我想得到每个 studid
的每个月的总数以及 total_p
和 total_a
的增量和减量总月数。
我的 Controller 代码是
foreach ($student as $student) {
if ($present == 0) {
$query = DB::table($wys_total_attend_table)
->where('studid', $student->id)
->where('smonth', '=', $date_exploded[1])
->where('syear', '=', $date_exploded[2])
->update([
'stotal_p' => DB::raw('stotal_p - 1'),
'stotal_a' => DB::raw('stotal_a + 1'),
]);
} elseif ($present == 1) {
$query = DB::table($wys_total_attend_table)
->where('studid', $student->id)
->where('smonth', '=', $date_exploded[1])
->where('syear', '=', $date_exploded[2])
->update([
'stotal_p' => DB::raw('stotal_p + 1'),
'stotal_a' => DB::raw('stotal_a - 1'),
]);
}
}
但它不起作用..
如何在查询构建器格式中使用 increment()
和 decrement()
?
for eg: if i 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.
最佳答案
increment() 和 decrement() 不返回 Query Builder 对象,因此您不能像在代码:
->increment('stotal_p', 1)->decrement('stotal_a', 1);
您需要分别调用每个方法。此外,1 是increment/decrement 的默认值,因此无需传递它。
这应该可以解决问题:
$query = DB::table($wys_total_attend_table)
->where('studid',$student->id)
->where('smonth','=',$date_exploded[1])
->where('syear','=',$date_exploded[2]);
$query->increment('stotal_a');
$query->decrement('stotal_p');
关于php - 如何在 laravel 中使用 increment() 和 decrement(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32110502/
我目前正在用 C++ 重新发明线程池的轮子。除了以下构造的多个实例之外,我已经从代码中消除了几乎所有的锁: std::atomic_size_t counter; void produce() {
嘿嘿,我知道如何在 SharedPreferences 中保存变量和其他数据,但我想知道如何每天递减一个变量。 这个 var (int) 已经在共享首选项中,并且我们每天递减 -1。 例如,我知道用户
我正在尝试解决 this UVa problem . 我正在尝试使用 Vector 来解决问题。我需要模拟循环链表之类的东西,所以我使用迭代器来访问元素。但是在尝试之后,我发现 Vector 迭代器在
在过去,我这样做: List _Items = GetItems(); int _CountDown = _Items.Count; using (BackgroundWorker _Worker =
我对 UIStepper 有一个奇怪的问题(它伴随着 UITextField) 考虑这个代码片段: @interface LTRPageTracker : UIView { UIStepp
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 Improve th
++ 增量 x = ++y // When y = 6 x = 6 x = y++ // And y = 6 x = 5 -- 递减 x = --y // W
我正在尝试创建一个成员函数,该函数应该使用列表来复制堆栈。所以我必须以相反的顺序打印列表的元素。我的头文件中有一个私有(private)列表声明为: class miniStackLT { priva
目前,我不得不写出多个for-loops,它们都执行相同的任务,不同之处在于中的初始化、条件和递减/递增>for-loops 本身。 这是我到目前为止的类似示例: if(some_bool_condi
我一定做了perl非常沮丧,因为它给了我一条错误消息,perldiag 中没有记录。 : PmmREFCNT_dec: REFCNT decremented below 0 for 53a6930!.
我有一个 pandas 系列如下... 0 2039-03-16 1 2056-01-21 2 2051-11-18 3 2064-03-05 4 2048-06-05 Name: BIRT
我正在尝试通过在我的 Controller 中使用内联来从我在数据库中的一个表中获取金额 public ActionResult IfPaid(int id) { Re
我们如何用 C 语言打印下面的模式?请解释一下逻辑。 1 12A 123BA 1234CBA 12345DCBA 1234
我在 DynamoDB 表中有一个类型为 Number 的键。我将操作设置为 ADD 以将值添加到现有值。 DynamoDBAttributeValue *attr =
在参数列表中调用 va_arg 时,我试图访问下一个或上一个元素。 “n”实际上是参数列表的长度。 va_list pointer; va_start(pointer, n); int temp =
我正在用左右两个按钮制作幻灯片,当单击按钮时,图像 src 发生变化,新图像出现。图像的位置存储在一个数组中,++ 运算符用于将照片移动到下一张,-- 用于上一张有时它不起作用我必须双击按钮工作。为什
到目前为止,我只是简单地使用“更改”来查看“数字”类型的输入字段是否已更改。但是,现在我需要知道数字是递增还是递减以执行不同的操作。我怎样才能看到号码是如何更改的? 寻找 JQuery 的解决方案,但
本文整理了Java中us.ihmc.yoVariables.variable.YoInteger.decrement()方法的一些代码示例,展示了YoInteger.decrement()的具体用法。
我想在表上有负的自动生成的键。 代替键:1,2,3,..,X我想要键:-1,-2,-3,...,-X 我需要这个,因为我必须创建一个镜像表以在 UNION 中与原始表一起使用,并“了解”哪些记录来自原
我有一张表 total_count +----+--------+-------+------+---------+---------+---------+ | id | studid | month
我是一名优秀的程序员,十分优秀!