如何使用laravel中的查询之间的数据库显示值

时间:2015-08-07 09:16:59

标签: laravel-4

这是我的表wys_attendence:

id   studid  adate  amonth  ayear  acls_id  attendence      
1    28      29     07      2015   10       1     
2    31      29     07      2015   10       0  
4    32      29     07      2015   10       1   
5    28      30     07      2015   10       0 
6    31      30     07      2015   10       1   
7    32      30     07      2015   10       1   
9    28      31     07      2015   10       1   
10   31      31     07      2015   10       1   
11   32      31     07      2015   10       1   
13   28      01     08      2015   10       1   
14   31      01     08      2015   10       0   
15   32      01     08      2015   10       1   
17   28      02     08      2015   10       0   
18   31      02     08      2015   10       1   
19   32      02     08      2015   10       1   
21   28      03     08      2015   10       1   
22   31      03     08      2015   10       1   
23   32      03     08      2015   10       0   
24   28      04     08      2015   10       1   
25   31      04     08      2015   10       1   
26   32      04     08      2015   10       0  

我想检查t_adates之间的值是否在表中,并显示t_adates之间的值

如果我选择29/07/2015 to 03/08/0215

我得到的输出不正确。这就是我得到的:

 studid  
  28     
  31     
  32    

不显示日期和相应的值

但我想这样:

studid  29  30 31 01 02  03
  28     1   0  1  1  0   1
  31     0   1  1  0  1   1
  32     1   1  1  1  1   0

我的控制器代码在这里

       `$startdate_exploded = explode("/",Input::get('curdate'));          
        $enddate_exploded = explode("/",Input::get('enddate'));              
        $curdate =  Input::get('curdate');
        $enddate =  Input::get('enddate');
        $teacher = WysTeacher::all();
        $attendance = DB::table('wys_teacherattendances')
                     ->whereBetween('t_adate', array($startdate_exploded[0], $enddate_exploded[0]))
                    ->whereBetween('t_amonth', array($startdate_exploded[1], $enddate_exploded[1]))
                    ->whereBetween('t_ayear', array($startdate_exploded[2], $enddate_exploded[2]))
                    ->groupBy('t_adate')
                    ->get();
       $teacher_daysattend=WysTeacherattendance::whereBetween('t_adate', array($startdate_exploded[0], $enddate_exploded[0]))
                    ->whereBetween('t_amonth', array($startdate_exploded[1], $enddate_exploded[1]))
                    ->whereBetween('t_ayear', array($startdate_exploded[2], $enddate_exploded[2]))  
                    ->get();`

我的 view.blade.php 代码在这里                        <table class="table table-hover" id="datatable"> @foreach($attendance as $attendances) <th>{{$attendances->t_adate}}</th> @endforeach </tr> @foreach($teacher as $teachers) <tr>
<td>{{$teachers->tname}}</td> @foreach($teacher_daysattend as $teacher_daysattends) @if($teachers->user_id == $teacher_daysattends->t_auserid) @if($teacher_daysattends->t_attendance == 1 ) <td><font color="green">1</font></td> @elseif($teacher_daysattends->t_attendance == 0) <td><font color="red">0</font></td>
@endif @endif @endforeach </tr> @endforeach </table>

如何修改我的查询以实现上述结果以及检查所有日期,月份广告年度。如果我选​​择日期(2015年7月29日至2015年8月3日)是否在数据库中,如果在数据库然后只显示一次并显示数据库中的所有详细信息?

0 个答案:

没有答案