gpt4 book ai didi

php - 带警告消息的 Laravel DB 查询

转载 作者:行者123 更新时间:2023-11-29 12:16:34 25 4
gpt4 key购买 nike

我想要的只是有一个超过缺席次数的 if 语句并显示消息。

这是 SQL 查询

public function countAbsent()
{

$absent = Attendances::select(DB::raw('count(status)'))
->where('student_id', '=', Auth::user()->id)
->where('status', '=', 'absent')
->where('section_name', 'like', Input::get('section_name'))
->where('subject_code', 'like', Input::get('subject_code'))
->count();

return View::make('student.view_absent')
->with('absent', $absent);


}

最佳答案

您可以传递另一个变量来查看:

public function countAbsent()
{

$absent = Attendances::select(DB::raw('count(status)'))
->where('student_id', '=', Auth::user()->id)
->where('status', '=', 'absent')
->where('section_name', 'like', Input::get('section_name'))
->where('subject_code', 'like', Input::get('subject_code'))
->count();

$absent_message = 'Students are not exceeding the absence threshold';

$threshold = 10; //whatever you like

if ($absent > $threshold)
{
$absent_message = 'Students are exceeding the absence threshold';
}

return View::make('student.view_absent')
->with('absent', $absent)
->with('absent_message', $absent_message);


}

并在 View student.view_absent 中回显 $absent_message

关于php - 带警告消息的 Laravel DB 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29711850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com