-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.php
51 lines (46 loc) · 1.16 KB
/
tools.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
<?php
function getRows($sql){
require_once('db_login.php');
try{
$response = $conn->query($sql);
$rows = [];
while($row = $response->fetch(PDO::FETCH_ASSOC)){
$rows[] = $row;
}
$response->closeCursor();
return $rows;
}
catch (PDOException $e){
print($e);
die();
}
}
function echoJson($sql){
$rows = getRows($sql);
echo json_encode($rows);
}
function echoTable($sql){
$rows = getRows($sql);
$table = "<table>";
/*
$table .= "<tr>";
$table .= "<th>rang</th>";
foreach ($rows[0] as $key => $value){
$table .= "<th>$key</th>";
}
$table .= "</tr>";
*/
$i=1;
foreach ($rows as $line){
$table .= "<tr>";
$table .= "<td>$i</td>";
$i++;
foreach ($line as $key => $value){
$table .= "<td>$value</td>";
}
$table .= "</tr>";
}
$table .= "</table>";
echo $table;
}
?>