-
Notifications
You must be signed in to change notification settings - Fork 2
/
functions.php
42 lines (31 loc) · 898 Bytes
/
functions.php
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
32
33
34
35
36
37
38
39
40
41
42
<?php
function getMySQLRows($conn, $stationName, $numRows) {
$sql = "(SELECT * FROM `$stationName` ORDER BY DateTime desc LIMIT $numRows) order by DateTime";
$result = mysqli_query($conn,$sql);
if(!$result){
exit("Select Query Error Description: ". mysqli_error($conn));
}
// put query in assoc array
$raw_array = array();
while($row = mysqli_fetch_assoc($result)) {
$raw_array[] = $row;
}
return $raw_array;
}
// return water year based on input date time string
function wtr_yr ($DATETIME, $START_MONTH=10) {
# Convert dates into POSIXlt
$datetime = strtotime($DATETIME);
$curYear = date("Y", $datetime);
$curMonth= date("m",$datetime);
# Year offset
if($curMonth >= $START_MONTH){
$offset = 1;
}
else{$offset = 0;}
# water year
$adjYear = $curYear+$offset;
# return water year
return $adjYear;
}
?>