我有一个数据库表WysTeacherattendance -table字段是(id t_adate t_amonth t_ayear t_attendance)
id t_adate t_amonth t_ayear t_attendance
1 15 07 2015 1
2 15 07 2015 1
3 15 07 2015 1
4 15 07 2015 1
5 15 07 2015 1
6 15 07 2015 1
7 15 07 2015 1
8 15 07 2015 1
9 15 07 2015 1
10 15 07 2015 1
我有10名教师,iam输入所有考勤人数为1,插入数据库t_attendance为1,所有10行。
当我输入提交按钮值进入数据库并重定向到另一个页面时,在检查所有t_attendance是否为1之前。
第一个条件
如果全部1转到主页。
id t_adate t_amonth t_ayear t_attendance
1 15 07 2015 1
2 15 07 2015 1
3 15 07 2015 1
4 15 07 2015 0
5 15 07 2015 1
6 15 07 2015 1
7 15 07 2015 0
8 15 07 2015 1
9 15 07 2015 1
10 15 07 2015 1
第二个条件
如果任何t_attendance值为0,请转到考勤页面。
如何检查这两个条件。
告诉我们它的控制器代码
foreach ($teachers as $teacher){
$teacheratt = new WysTeacherattendance();
$teacheratt->t_auserid = $teacher->user_id;
$teacheratt->t_adate=$date_exploded[0];
$teacheratt->t_amonth=$date_exploded[1];
$teacheratt->t_ayear=$date_exploded[2];
$teacheratt->t_attendance=Input::get($teacher->user_id);
$teacheratt ->save();
}
if($users = DB::table('wys_teacherattendances')
->where('t_adate',$date_exploded[0])
->whereIn('t_attendance', array(1))->get())
{return Redirect::route('GetTeachersearchAttendence')
->with('success',' teacher exist');
}
if($users = DB::table('wys_teacherattendances')
->where('t_adate',$date_exploded[0])
->where('t_attendance', '=',0)->get())
{return Redirect::route('AddTeacherabsentReason',$date_exploded[0])
->with('success',' teacher exist');
}
}`
but only work this condition `if($users = DB::table('wys_teacherattendances')
->where('t_adate',$date_exploded[0])
->whereIn('t_attendance', array(1))->get())
{return Redirect::route('GetTeachersearchAttendence')
->with('success',' teacher exist');
}
如何解决?
答案 0 :(得分:0)
试试这个
if($users == DB::table('wys_teacherattendances')
->where('t_adate',$date_exploded[0])
->whereIn('t_attendance', array(1))->get())
{return Redirect::route('GetTeachersearchAttendence')
->with('success',' teacher exist');
}
对于比较结果,您必须使用==,而不是=(=赋值,不检查值)
我认为你必须改变所有" ="您输入了" =="
我只是提出这个想法 您可以查看该教师的人数
$teacher_number = "SELECT COUNT(teacher) from teacher"
您可以查看出席人数
$attendance = "SELECT COUNT(attendance) from attendance where
attendance = 1 and date = yourdate"
if $teacher_number == $attendance
redirect home.page
else if $teacher_number > $attendance
redirect attendance.page