how to display values from database using between query in laravel - laravel-4

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?

Related

remove rows based on multiple columns values in awk

I am trying to remove rows based on 4th column value is equal to 7 and 5th column value less than 30 from my text file using awk.
Here is my text file
1 1 2017 7 00 00 95.197469 112.803277
1 1 2017 7 05 00 94.139040 113.255244
1 1 2017 7 10 00 93.084220 113.715022
1 1 2017 7 15 00 92.033141 114.182867
1 1 2017 7 20 00 90.985940 114.659045
1 1 2017 7 25 00 89.500772 115.143830
1 1 2017 7 30 00 88.574990 115.637504
1 1 2017 7 35 00 87.614221 116.140360
1 1 2017 7 40 00 86.633495 116.652701
1 1 2017 7 45 00 85.642547 117.174839
1 1 2017 7 50 00 84.647055 117.707097
1 1 2017 7 55 00 83.650410 118.249809
1 1 2017 8 00 00 82.654745 118.803319
1 1 2017 8 05 00 81.661486 119.367982
1 1 2017 8 10 00 80.671646 119.944164
1 1 2017 8 15 00 79.685987 120.532243
1 1 2017 8 20 00 78.705118 121.132609
1 1 2017 8 25 00 77.729550 121.745662
1 1 2017 8 30 00 76.759731 122.371816
1 1 2017 8 35 00 75.796072 123.011494
1 1 2017 8 40 00 74.838956 123.665132
1 1 2017 8 45 00 73.888755 124.333179
1 1 2017 8 50 00 72.945832 125.016092
1 1 2017 8 55 00 72.010551 125.714342
1 1 2017 9 00 00 71.083276 126.428408
With awk:
awk '$4!=7 || $5>=30 {print}' file
Output:
1 1 2017 7 30 00 88.574990 115.637504
1 1 2017 7 35 00 87.614221 116.140360
1 1 2017 7 40 00 86.633495 116.652701
1 1 2017 7 45 00 85.642547 117.174839
1 1 2017 7 50 00 84.647055 117.707097
1 1 2017 7 55 00 83.650410 118.249809
1 1 2017 8 00 00 82.654745 118.803319
1 1 2017 8 05 00 81.661486 119.367982
1 1 2017 8 10 00 80.671646 119.944164
1 1 2017 8 15 00 79.685987 120.532243
1 1 2017 8 20 00 78.705118 121.132609
1 1 2017 8 25 00 77.729550 121.745662
1 1 2017 8 30 00 76.759731 122.371816
1 1 2017 8 35 00 75.796072 123.011494
1 1 2017 8 40 00 74.838956 123.665132
1 1 2017 8 45 00 73.888755 124.333179
1 1 2017 8 50 00 72.945832 125.016092
1 1 2017 8 55 00 72.010551 125.714342
1 1 2017 9 00 00 71.083276 126.428408
Perhaps a more concise awk
Removing line where field 4 equals 7 and field 5 less than 30
$ awk '!($4==7 && $5<30)' case_file_48485025
Output
1 1 2017 7 30 00 88.574990 115.637504
1 1 2017 7 35 00 87.614221 116.140360
1 1 2017 7 40 00 86.633495 116.652701
1 1 2017 7 45 00 85.642547 117.174839
1 1 2017 7 50 00 84.647055 117.707097
1 1 2017 7 55 00 83.650410 118.249809
1 1 2017 8 00 00 82.654745 118.803319
1 1 2017 8 05 00 81.661486 119.367982
1 1 2017 8 10 00 80.671646 119.944164
.
.
How it works
By default awk prints a line if it sees a non-zero value as its command
!($4==7 && $5<30) would evaluate to zero when your condition is met and hence awk doesn't print.
This might work for you (GNU sed):
sed '/^.........7.[0-2]/d' file
Delete a line that has a 7 in the 4th column and 0 to 2 as the first character of the 5th column.

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

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.

Range with leading zero in bash

How to add leading zero to bash range?
For example, I need cycle 01,02,03,..,29,30
How can I implement this using bash?
In recent versions of bash you can do:
echo {01..30}
Output:
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
Or if it should be comma separated:
echo {01..30} | tr ' ' ','
Which can also be accomplished with parameter expansion:
a=$(echo {01..30})
echo ${a// /,}
Output:
01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30
another seq trick will work:
seq -w 30
if you check the man page, you will see the -w option is exactly for your requirement:
-w, --equal-width
equalize width by padding with leading zeroes
You can use seq's format option:
seq -f "%02g" 30
A "pure bash" way would be something like this:
echo {0..2}{0..9}
This will give you the following:
00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
Removing the first 00 and adding the last 30 is not too hard!
This works:
printf " %02d" $(seq 1 30)

Resources