How to display database values once in view page using laravel - laravel-4

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.?

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();

Related

Shell Script to print a calendar after the user specifies the month and a day

*****Shell Script*******
Given a month and the day of the week that's the first of that month, print a calendar for the month. (Remember, number of days in months is different and use \n to go to a new line.)
Unix has a cal command especially for this purpose.
By default, cal shows the current month's calendar.
mayankp#mayank:~/$ cal
November 2018
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30
If you want a calendar for a specific month of a specific year, do this:
mayankp#mayank:~/$ cal 1 2018
January 2018
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
This displays the calendar for January 2018.
So, your shell script would be:(ex: calendar.sh)
#!/usr/bin/env bash
month=$1
year=$2
cal $1 $2
Run the script like this:
mayankp#mayank:~/$ sh calendar.sh 3 2018
March 2018
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Let me know if this helps.

Sort a marix by timestamp

I am not sure if that applicable but I need to arrange and sort below output by timestamp below in column 2 under From , the newer should be on first line and the older on last line, what is needed is to keep the time format as it is, only I need to arrange by date
COUNT FROM TO
97 Oct 10 10:00:56 Oct 10 10:18:35
9 Mar 10 10:02:09 Oct 10 10:02:55
768 Oct 10 10:01:09 Oct 10 10:18:24
764 Oct 10 10:00:53 Oct 10 10:18:24
33 Oct 10 10:18:35 Oct 10 10:18:39
306 May 10 10:00:52 Oct 10 10:21:20
3 Oct 10 10:00:52 Oct 10 10:00:52
3 Oct 12 15:33:26 Nov 2 03:30:06
2 Oct 17 09:16:53 Oct 17 09:17:05
18 Nov 2 00:07:24 Nov 2 01:03:13
11 Oct 10 10:00:52 Oct 10 10:00:56
10095 Jun 10 10:00:52 Oct 10 10:18:24
10 Oct 10 10:18:40 Oct 10 10:18:45
1 Nov 2 03:21:32 Nov 2 03:21:32
1 Feb 2 01:31:53 Nov 2 01:31:53
1 Aug 2 03:26:24 Nov 2 03:26:24
1 Nov 2 03:21:32 Nov 2 03:21:32
1 Oct 10 10:18:05 Oct 10 10:18:05
1 Oct 17 09:16:52 Oct 17 09:16:52
1 Jan 10 10:02:55 Oct 10 10:02:55
1 Nov 2 23:24:09 Nov 2 23:29:09
1 Oct 10 10:00:52 Oct 10 10:00:52
1 Oct 10 10:00:53 Oct 10 10:00:53
1 Nov 2 03:22:22 Nov 2 03:22:22
1 Apr 2 06:41:29 Nov 2 06:41:29
The output should be with the same header with below as first line
1 Nov 2 23:24:09 Nov 2 23:29:09
, and below as the last line.
1 Jan 10 10:02:55 Oct 10 10:02:55
Take a look at man sort and you will see that you can sort by columns using the -k option.
This option supports a column number, and optional sort method.
For your case this might work:
sort -k2Mr -k3nr -k4r file.txt
-k2Mr do month sort on column two and reverse it.
-k3nr do numeric sort on column three and reverse it.
-k4r sort on column four and reverse it.

how to display values from database using between query in laravel

This is my table 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
I want to check if values between the t_adates is in the table, and to display values from between the t_adates
if I am select 29/07/2015 to 03/08/0215.
The output I get is incorrect. This is what I get:
studid
28
31
32
not display dates and corresponding values
But I want it like this:
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
my controller code is here
`$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();`
my view.blade.php code is here
<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>
How can I modify my query to achieve the above result as well as check all day ,month ad year.if iam select dates (29/07/2015 to 03/08/2015 ) are in the database or not if in database then day display only once and display all details from database?

how to display 2 month values in correct order 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 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 06 08 2015 10 1
14 31 06 08 2015 10 0
15 32 06 08 2015 10 1
17 28 07 08 2015 10 0
18 31 07 08 2015 10 1
19 32 07 08 2015 10 1
21 28 08 08 2015 10 1
22 31 08 08 2015 10 1
23 32 08 08 2015 10 0
24 28 12 08 2015 10 1
25 31 12 08 2015 10 1
26 32 12 08 2015 10 0
I want to check if values between the t_adates is in the table, and to display values from between the t_adates
if I am select 1/07/2015 to 31/08/0215.
The output I get is incorrect. This is what I get:
studid 2/07/2015 06/08/2015 07/08/2015 08/08/2015 30/07/205 31/07/2015
28 1 1 0 1 0 1
31 0 0 1 1 1 1
32 1 1 1 0 1 1
not display values are incorrect order
But I want it like this:
studid 2/07/2015 30/07/205 31/07/2015 06/08/2015 07/08/2015 08/08/2015
28 1 0 1 1 0 1
31 0 1 1 0 1 1
32 1 1 1 1 1 0
my controller code is here
`$startdate_exploded = explode("/",Input::get('curdate'));
$enddate_exploded = explode("/",Input::get('enddate'));
$attendence_tbl = WysAttendancename::where('cls_id',$id)->first();
$wys_attendence_table = $attendence_tbl->attendance_name;
$attendance = DB::table($wys_attendence_table)
->whereBetween('adate', array($startdate_exploded[0], $enddate_exploded[0]))
->whereBetween('amonth', array($startdate_exploded[1], $enddate_exploded[1]))
->whereBetween('ayear', array($startdate_exploded[2], $enddate_exploded[2]))
->groupBy('adate')
->get();
$stud_attend = DB::table($wys_attendence_table)
->whereBetween('adate', array($startdate_exploded[0], $enddate_exploded[0]))
->whereBetween('amonth', array($startdate_exploded[1], $enddate_exploded[1]))
->whereBetween('ayear', array($startdate_exploded[2], $enddate_exploded[2]))
->get();`
my view.blade.php is
`<td>Student Name</td>
#foreach($attendance as $attendances)
<td><font size="-1">{{$attendances->adate}}-{{$attendances->amonth}}-{{$attendances->ayear}}</font></td>
#endforeach
</tr>
#foreach($students as $student)
#if($student->studcls == $id)
<tr>
<td>{{$student->studname}}</td>
#foreach($stud_attend as $stud_attends)
#if($student->id == $stud_attends->studid)
#if($stud_attends->attendence == 1)
<td><font color="green" size="3">p</font></td>
#elseif($stud_attends->attendence == 0)
<td><font color="red" size="3">a</font></td>
#endif
#endif
#endforeach
</tr>
#endif
#endforeach`
How can I modify my query to achieve the above result as well as check all dates (01/07/2015 to 31/08/2015 ) are in the database or not if in database then day display only once and display all details in from database?
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();

epoch time comparison bsd / MacOSX

This should be obvious to all but me,
I have a file full of epoch timestamps and I'm trying to get the records from the last 7 days.
So I tried this in my mac:
PAST=$(gdate -d "7 days ago" +%s)
if [ $timeval -gt $PAST ]; then
do stuff
fi
Example erroneous output:
TS from data, Human fr data, TS from $PAST, Human from $PAST
1419981977690,Tue Jun 9 06 14 50 PST 46967,1421129827,Mon Jan 12 22 17 07 PST 2015
1419400311440,Thu Jan 2 00 17 20 PST 46949,1421129827,Mon Jan 12 22 17 07 PST 2015
1420341489480,Fri Oct 30 06 38 00 PST 46978,1421129827,Mon Jan 12 22 17 07 PST 2015
1421232275040,Thu Jan 22 07 04 00 PST 47007,1421129827,Mon Jan 12 22 17 07 PST 2015
The timestamps in your file are in milliseconds, not seconds. Divide them by 1000.

Resources