-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollections.php
42 lines (33 loc) · 916 Bytes
/
collections.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
$collections=null;
$message=null;
$pdo = new PDO('sqlite:'.getcwd().'/db/wims.sqlite');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
#$sql = 'SELECT * FROM collection';
$sql = 'SELECT collection.id, collection.name, collection.type, collection.color, count(DISTINCT point.id) as points FROM collection left join point on collection.id = point.collectionid
group by collection.id';
try {
$sth = $pdo->prepare($sql);
$sth->execute();
$collections = $sth->fetchAll();
$sth = null;
}
catch (PDOException $e) {
$message=$e->getMessage();
}
include 'vendor/autoload.php';
try
{
$loader = new Twig_Loader_Filesystem('templates');
$twig = new Twig_Environment($loader);
$template = $twig->loadTemplate('collections.html');
echo $template->render(array (
'message' => $message,
'collections' => $collections
));
}
catch (Exception $e)
{
die ('ERROR: ' . $e->getMessage());
}
?>