-
Notifications
You must be signed in to change notification settings - Fork 0
/
utility.php
44 lines (42 loc) · 1.09 KB
/
utility.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
<?php
function sanitize($input) {
$data = trim($input);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
function requestVar($var, $default = NULL) {
if (isset($_REQUEST[$var])) {
return sanitize($_REQUEST[$var]);
} else {
return $default;
}
}
function sqlResultToHtmlTable($sqlresult, $delim="\n") {
//https://stackoverflow.com/a/26891213/1431237
// starting table
$htmltable = "<table>" . $delim ;
$counter = 0 ;
// putting in lines
while ($row = $sqlresult->fetch_assoc()) {
if ($counter===0) {
// table header
$htmltable .= "<tr>" . $delim;
foreach ($row as $key => $value ) {
$htmltable .= "<th>" . $key . "</th>" . $delim;
}
$htmltable .= "</tr>" . $delim;
$counter = 22;
}
// table body
$htmltable .= "<tr>" . $delim;
foreach ($row as $key => $value) {
$htmltable .= "<td>" . $value . "</td>" . $delim;
}
$htmltable .= "</tr>" . $delim;
}
// closing table
$htmltable .= "</table>" . $delim;
// return
return $htmltable;
}