-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.php
76 lines (69 loc) · 1.51 KB
/
query.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!doctype html><html><head>
<meta charset=utf8>
<title>query</title>
<style>
body{
background:white;
}
td{
white-space:nowrap;
font-family:monospace;
font-size:smaller;
}
th{
text-align:left;
}
</style>
</head><body>
<nav><a href="index.php">← Home</a></nav><hr>
<h2>UWWTD query</h2><hr>
<?php
//GET ?query=query default value
$query = isset($_GET["query"]) ? $_GET["query"] : false;
if(!$query){
//default query
$query="
SELECT *
FROM UWWTD_TreatmentPlants
WHERE uwwBeginLife LIKE '19%'
LIMIT 10;
";
}
//display sql query text
echo "<code>$query</code>";
//connect with database
$db = new SQLite3("UWWTD_TreatmentPlants.gpkg.sqlite",SQLITE3_OPEN_READONLY);
//execute actual query
$res = $db->query($query) or die(print_r($db->lastErrorMsg(), true));
//count and display number of results
function num_rows($res){
$nrows=0;
$res->reset();
while($res->fetchArray()) $nrows++;
$res->reset();
return $nrows;
}
$n = num_rows($res);
echo "
<hr>$n results
";
?>
<table border=1><?php
//render table with results
$i=0;
while($row=$res->fetchArray(SQLITE3_ASSOC)){
if($i==0){
echo "<tr style='position:sticky;top:0;background:white'>";
foreach(array_keys($row) as $key){
echo "<th>$key</th>";
}
echo "</tr>";
}
echo "<tr>";
foreach($row as $key=>$val){
echo "<td>$val</td>";
}
echo "</tr>";
$i++;
}
?></table>