cnbwd
cnbwd

Reputation: 379

How to display database values once in view page using laravel

This is my table wys_attendence:

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

I want to check if every day of a specific year and month is in the table, and to display all the dates of a selected month and year.

if I am select july 2015.

The output I get is incorrect. This is what I get:

studid 02 02 02 13 13 13 14 14 14 15 15 15 16 16 16 17 17 17

But I want it like this:

studid  2  13 14 15 16  17

my controller code is here

       `$amonth = Input::get('amonth');
        $ayear = Input::get('ayear');
        $teacher_attend=WysTeacherattendance::all();
        $attendance = DB::table('wys_teacherattendances')
                        ->where('t_amonth', $amonth)
                        ->where('t_ayear',$ayear)
                        ->get();`

my view.blade.php code is here <th>studid</th> @foreach($attendance as $attendances) <th>{{$attendances->t_adate}}</th> @endforeach

How can I modify my query to achieve the above result as well as check if days of my selected month and year are in the database or not if in database then day display only once.?

Upvotes: 0

Views: 101

Answers (1)

smbdevin
smbdevin

Reputation: 172

If you want to group records by date then use groupBy() as explained on http://laravel.com/docs/4.2/queries#selects

$attendance = DB::table('wys_teacherattendances')
->where('t_amonth', $amonth)
->where('t_ayear',$ayear)
->groupBy('t_adate')
->get();

Upvotes: 2

Related Questions