-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.php
39 lines (35 loc) · 835 Bytes
/
graph.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
<?php
// $dbhandle = sqlite_open('event.db', 0666, $error);
// $query = sqlite_query($dbhandle, "SELECT * from Event");
include_once("conf.php");
try
{
$db = new PDO('sqlite:'.$db_name);
$sql = "SELECT * FROM $event_table";
$stmt = $db->prepare($sql);
$stmt->execute();
}
catch(PDOException $e)
{
echo $e->getMessage();
}
$stats = array();
$total=0;
while ($val = $stmt->fetchall(PDO::FETCH_ASSOC)) {
foreach($val as $row){
if (!array_key_exists($row['call'], $stats)){
$stats[$row['call']]['points']=0;
}
$total += $row['points'];
$stats[$row['call']]['points'] += $row['points'];
}
$rows = array();
foreach ($stats as $i => $value){
$r[0] = $i;
$val = (($value['points'] / $total) * 100.00);
$r[1] = $val;
array_push($rows,$r);
}
}
print json_encode($rows);
?>