I have a Openinghours Table and I want to query through so that I get the closing time of a Location.
Here is an instance of the OpeningHoursTable and my code current query Code, that dosn't work, however you might get an Idea...
For instance day_id = 3,
is open from 11:30 till 14:30. and from 17:30 till 00:00 next Day.
I Woud like to have 0000 of day 4 outputted
How can I query this?
Database entries:
location_id | day_id | opened | closed
81 1 1130 1430
81 1 1730
81 2 0000
81 3 1130 1430
81 3 1730
81 4 0000
81 4 1130 1430
81 4 1730
81 5 0000
81 5 1130 1430
81 5 1730
81 6 0000
81 6 1130 1430
81 6 1730
81 7 0000
81 7 1130 1430
81 7 1730
81 1 0000
My "idea" of Code in Location.php :
public function closesTodayAt($closeTo = 2000)
{
$thisDay = today()->dayOfWeek + 1;
$time = $this->openinghours()->where('day_id', $thisDay)->where('closed','!=', "")
orWhere()->get();
if ($time->first()->closed < $closeTo ) {
#code
}
if ($time < $closeTo ) {
$nextDay = today()->addDay(1)->dayOfWeek +1;
$time = $this->openinghours()->where('day_id', $thisDay)->where('opened','!=',"")->first()->opened;
}
if ($time === "0000") {
# code...
}
$time = str_split($time,2);
$time = implode(":", $time);
return $time;
}
Here another part of the Database:
94 1 1100
94 2 0100
94 2 1100
94 3 0100
94 3 1100
94 4 0100
94 4 1100
94 5 0100
94 5 1100
94 6 0200
94 6 1100
94 7 0400
94 7 1100
94 1 0400
If I'm reading this right, the closing hours would always be the earliest found hours of the next day, so simply taking the hours for the next day, sorting and taking the first record would get you the closing time:
public function scopeCloses($query)
{
$nextDayOfWeek = now()->addDay()->dayOfWeek;
$hours= $this->openinghours->where('day_id', $nextDayOfWeek)
->sortBy('closes')
->first();
return $hours->closes;
}
Related
I have a problem trying using for loop inside a loop i can't get the result i want
<?php
for($sg = 1; $sg <= 11; $sg++){
echo "<b>".echo $sg;."</b>";
for($g = 1; $g <= 11; $g++){
echo "<p>".echo $g."</p>";
}
?>
I looking the result to be like
1
1 2 3 4 5 6 7 8 9 10 11
2
12 13 14 15 16 17 18 19 20
3
21 22 23 24 25 26 27 28 29 30
continuous ....
<?php
for($sg = 1; $sg <= 11; $sg++){
echo "<br /> <b>". $sg."</b> ";
for($g = 1+(10*($sg-1)); $g <= (10*($sg-1))+10; $g++){
echo "". $g." ";
}
}
?>
Output:
1 1 2 3 4 5 6 7 8 9 10
2 11 12 13 14 15 16 17 18 19 20
3 21 22 23 24 25 26 27 28 29 30
4 31 32 33 34 35 36 37 38 39 40
5 41 42 43 44 45 46 47 48 49 50
6 51 52 53 54 55 56 57 58 59 60
7 61 62 63 64 65 66 67 68 69 70
8 71 72 73 74 75 76 77 78 79 80
9 81 82 83 84 85 86 87 88 89 90
10 91 92 93 94 95 96 97 98 99 100
11 101 102 103 104 105 106 107 108 109 110
<?php
$inner_start = 1;
$inner_max = 11;
for($sg = 1; $sg <= 11; $sg++){
echo "<b>".$sg."</b></br>";
echo "<p>";
for($g = $inner_start; $g <= $inner_max; $g++){
echo $g . ' ';
}
$inner_start = $inner_start + 10;
$inner_max += 10;
echo "</p></br>";
}
?>
I'm doing social service, the idea is to automatize a process. I already capture other values using regex, like:
<?php function LeerEncabezado() {
$fh = fopen('RPREGFM_________007_001.txt', 'r') or die('lel'); $file =
str_replace(',', '',
file_get_contents("RPREGFM_________007_001.txt")); $f =
fopen("RPREGFM_________007_001.txt", "w"); fwrite($f, $file);
fclose($f); while (!feof($fh)) {
$line = fgets($fh);
//Intermedio
if (preg_match('/INTERMEDIO (?<cfintermedio>[\w]+.+)/i', $line, $r1)) {
$CFINTERMEDIO = substr($r1['cfintermedio'], 13, 8);
echo "C.F. Intermedio: $CFINTERMEDIO";
echo '<br/>';
}
//Base
if (preg_match('/BASE (?<cfbase>[\w]+.+)/i', $line, $r2)) {
$CFBASE = substr($r2['cfbase'], 13, 8);
echo "C.F. Base: $CFBASE";
echo '<br/>';
}
//kVArh
if (preg_match('/F.P. (?<fp>[\d]+.+)/i', $line, $r3)) {
$anioi = substr($r3['fp'], 0, 5);
echo "kVArh: $anioi";
echo '<br/>';
echo "--------------------------------------</br>";
}
//Base promedio
if (preg_match('/201912 (?<fp>[\d]+.+)/i', $line, $r3)) {
$anioi = substr($r3['fp'], 8, 5); // echo "kVArh: $anioi";
echo '<br/>';
echo "--------------------------------------</br>";
}
} } LeerEncabezado();
fclose($fh);
And it's working until his point, I got to take 3 values from that text block, the last number in INTERM column, BASE and % M$. In this receipt, it would be 1,5,99.98%. I've used strg_replace before for, I guess ill use it for the %. So I can compare those variables with other in the same receipt.
How can I extract those value taking in mind that the 201912 it's going to change taking in consideration the year and the number of rows in MES might change? Pretty much used the blank space and the read the previous line which it's going to be the one where the 3 values are in?
MES TOTAL PUNTA INTERM BASE TOT PTA INT BAS % M$
201901 9 1 7 744 122 622 99.96
201902 8 1 6 672 107 565 99.97
201903 9 1 7 744 115 629 99.97
201904 9 2 7 719 122 597 99.97
201905 10 1 8 744 88 656 99.98
201906 10 1 8 720 80 640 99.97
201907 12 2 10 744 92 652 98.89
201908 13 2 11 744 88 656 97.74
201909 11 1 9 720 80 640 97.05
201910t 1 7 624 76 548 97.56
201910 10 1 120 20 100 98.80
201911 8 1 6 721 115 606 99.20
201912 7 1 5 744 117 627 99.98
I have a problem with that script using the simulation calculation:
$no3=+1;
for ($i=0; $i<36; $i++)
{
$ No = + 1;
for ($ i = 0; $ i <36; $ i ++) {
enter code here
$ No3 ++;
}
Example :
No GradeA GradeB Total
1 5 5 10
2 10 5 15
3 15 5 20
4 20 5 25
5 25 5 30
6 30 5 35
7 35 5 40
8 40 5 45
9 45 5 50
10 50 5 55
11 55 5 60
12 60 5 65
13 65 5 70
14 70 10 80
15 80 10 90
16 90 10 100
17 100 10 110
18 110 10 120
19 120 10 130
20 130 10 140
21 140 10 150
22 150 10 160
23 160 10 170
24 170 10 180
25 180 10 190
26 190 20 210
27 210 20 230
28 230 20 250
29 250 20 270
30 270 20 290
31 290 20 310
32 310 20 330
33 330 20 350
34 350 20 370
35 370 20 390
36 380 20 410
$no3++;
}
how do I make the numbers 12,24 and 36 there is the text
Try this:
this is answer for your secound question to
<?php
$two = 5;
$three = 5;
$four = 10;
$mod = 14;
for ($i = 1; $i <=36; $i ++) {
echo $i."\t".$two."\t".$three."\t".$four."\n";
if($i % $mod == 0){
$three *= 2;
}
$two += $three;
$four += $three;
}
?>
I am trying to create an un-ordered list of weekly dates. But these dates should only populated what is applicable. In my db i have entries with dates ranging from 10/17 - 11/5.
the idea is to get the first date available then search for it and create the 1st week
<li>date - date</li>
Then add a week and search for a date in that week and print the following week sequence, then add a week, etc...
Below is my code:
$fromDt_info = mysqli_query($con,"SELECT * FROM " . $rec_table . " WHERE `date`='".$from_dt."'" );
echo '<ul>';
while($row = mysqli_fetch_array($fromDt_info)){
echo $row['0'];
$to_dt = date('Y-m-d',strtotime($from_dt . '+ 6 Days'));
echo '<li>'.date('m/d/Y',strtotime($from_dt)).' - '.date('m/d/Y',strtotime($to_dt)).'</li>';
$from_dt = date('Y-m-d',strtotime($from_dt . '+ 7 Days'));
//empty array somehow? Prints as many emtries for first date only. But prints updated dates in sequance.
}
echo '</ul>';
This is the result i am getting:
44 10/17/2014 - 10/23/2014
45 10/24/2014 - 10/30/2014
46 10/31/2014 - 11/06/2014
47 11/07/2014 - 11/13/2014
48 11/14/2014 - 11/20/2014
you can see it's printing two extra lines that i don't have entries for.
When i added the echo $row['0']; to print the id, then i noted it's printing all of the entries for the first date, which is five entries on that first date, but the dates printed are squential not relating to the id entry.
Do i need to somehow empty the array at the end of the while statement?
This is the Data in my db:
id date
44 2014-10-17
45 2014-10-17
46 2014-10-17
47 2014-10-17
48 2014-10-17
51 2014-10-20
52 2014-10-20
53 2014-10-20
55 2014-10-20
56 2014-10-20
57 2014-10-20
58 2014-10-21
59 2014-10-21
60 2014-10-21
61 2014-10-21
62 2014-10-21
63 2014-10-21
64 2014-10-21
65 2014-10-22
66 2014-10-22
67 2014-10-22
68 2014-10-22
69 2014-10-23
70 2014-10-23
71 2014-10-23
72 2014-10-24
73 2014-10-24
278 2014-10-27
279 2014-10-27
280 2014-10-27
281 2014-10-27
282 2014-10-27
283 2014-10-27
284 2014-10-27
285 2014-10-28
286 2014-10-28
287 2014-10-28
288 2014-10-29
289 2014-10-29
290 2014-10-29
291 2014-10-29
293 2014-10-30
294 2014-10-30
295 2014-10-30
296 2014-10-30
297 2014-10-30
298 2014-10-30
299 2014-10-31
300 2014-10-31
301 2014-10-31
302 2014-10-31
303 2014-10-31
304 2014-10-31
305 2014-11-03
306 2014-11-03
307 2014-11-03
308 2014-11-03
309 2014-11-04
310 2014-11-04
311 2014-11-04
312 2014-11-04
313 2014-11-04
314 2014-11-05
315 2014-11-05
316 2014-11-05
317 2014-11-05
318 2014-11-05
319 2014-11-05
320 2014-11-05
I have this code to get records between two dates $date1 and $date2
for ($i=$date1;$i<$date2;$i++){//BETWEEN THE TWO DATES
$count_rcvd=mysql_num_rows(mysql_query("select * from cards where Date_Rcvd='$i'"));
$count_collect=mysql_num_rows(mysql_query("select * from cards where Date_Collected='$i'"));
if($i==$date1){FOR THE FIRST DATE IN THE RANGE
$uncollected=mysql_num_rows(mysql_query("select * from cards where Status='AVAILABLE' and Date_Rcvd<='$i'"));
$balance=$uncollected;
}
else{//FOR CONSECUTIVE DATES AFTER DATE1
$uncollected=mysql_num_rows(mysql_query("select * from cards where Status='AVAILABLE' and Date_Rcvd<'$i'"));//previous days balance
$balance=$uncollected+$count_rcvd-$count_collect;
When i echo for $i
echo "";
echo $i;
echo "";
echo $count_rcvd;
echo "";
echo $count_collect;
echo "";
echo $balance;
echo "";
I get out below with the date going well beyond the calender dates
014-03-15 0 7 103
2014-03-16 0 3 100
2014-03-17 0 7 96
2014-03-18 0 9 94
2014-03-19 0 5 98
2014-03-20 15 6 112
2014-03-21 0 6 103
2014-03-22 0 1 108
2014-03-23 0 0 109
2014-03-24 0 8 101
2014-03-25 0 3 106
2014-03-26 0 0 109
2014-03-27 1 2 108
2014-03-28 0 0 110
2014-03-29 6 1 115
2014-03-30 0 0 116
2014-03-31 0 0 116
2014-03-32 0 0 116
2014-03-33 0 0 116
2014-03-34 0 0
the problem is the output dates go beyond 31st for example....HELP!!!
To iterate on dates, i recommand you to use DateTime and DateTimeInterval classes (Be careful ! PHP 5.3 minimum) : http://www.php.net/manual/fr/class.datetime.php
You can add days/months following the real calendar : http://www.php.net/manual/fr/datetime.add.php