-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.php
More file actions
31 lines (20 loc) · 872 Bytes
/
data.php
File metadata and controls
31 lines (20 loc) · 872 Bytes
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
<?php
require('db.php');
$sth = $pdo->prepare("SELECT * FROM bodies ORDER BY bodies.order ASC");
$sth->execute(array($date));
$planets = $sth->fetchAll();
$date = date('Y-m-d');
$start_date = date('Y-m-d', strtotime($date.' - 365 days'));
$end_date = date('Y-m-d', strtotime($date.' + 365 days'));
// Select 1 day per week (today's weekday) to limit results
foreach ($planets as $planet) {
$sth = $pdo->prepare("SELECT record_date, elon, distance FROM bodies_data
WHERE body_id = ? AND DAYOFWEEK(record_date) = DAYOFWEEK(?)
AND record_date >= ? AND record_date <= ?
ORDER BY record_date ASC");
$sth->execute(array($planet->id, $date, $start_date, $end_date));
$records = $sth->fetchAll();
$planet->records = $records;
}
echo json_encode($planets);
?>