-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest7getdata.php
42 lines (35 loc) · 948 Bytes
/
test7getdata.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
<?php
$servername = "localhost";
$username = "*****";
$password = "*****";
$dbname = "****";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
echo "ERROR CONNECTING";
die ("connection failed: " . $conn->connect_error);
echo "ERROR CONNECTING";
}
$sql = "SELECT IP, COUNT(*) as TOT FROM srlog s GROUP BY IP ORDER BY TOT DESC;";
$ret = "{
\"cols\": [
{\"id\":\"\",\"label\":\"IP\",\"pattern\":\"\",\"type\":\"string\"},
{\"id\":\"\",\"label\":\"TOT\",\"pattern\":\"\",\"type\":\"number\"}
],
\"rows\": [
";
$result = $conn->query($sql);
$cnt = 0;
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$cnt = $cnt + 1;
if ($cnt > 1 ) $ret = $ret . ",";
$ret = $ret . "{\"c\":[{\"v\":\"". $row["IP"] . "\",\"f\":null},{\"v\":". $row["TOT"]. ",\"f\":null}]}";
}
} else {
echo "0 results";
}
$ret = $ret . "]
}";
$conn->close();
echo $ret;
?>