-
Notifications
You must be signed in to change notification settings - Fork 1
/
hearts.php
23 lines (19 loc) · 974 Bytes
/
hearts.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
// CREATE TABLE hearts (deviceId TINYTEXT NOT NULL, presentatieId int NOT NULL, CONSTRAINT c_pairs UNIQUE (presentatieId, deviceId));
// DELETE FROM hearts;
if ($_SERVER["REQUEST_METHOD"] === "POST" && $_POST["deviceId"] && $_POST["presentatieId"]) {
$deviceId = $_POST["deviceId"];
$presentatieId = (int) $_POST["presentatieId"];
if (isset($_POST["hearted"]) && $_POST["hearted"] === "true") {
$sql = "INSERT OR IGNORE INTO hearts (deviceId, presentatieId) VALUES ('{$deviceId}', {$presentatieId});";
} else {
$sql = "DELETE FROM hearts WHERE deviceId = '{$deviceId}' AND presentatieId = {$presentatieId};";
}
$pdo = new PDO('sqlite:db/hearts.db');
$rs = $pdo->query($sql);
}
$sql = "SELECT presentatieId, COUNT(*) as count FROM hearts GROUP BY presentatieId;";
$pdo = new PDO('sqlite:db/hearts.db');
$rs = $pdo->query($sql);
header("Content-type: application/json");
echo json_encode($rs->fetchAll(PDO::FETCH_ASSOC));