-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_tasks.php~
47 lines (39 loc) · 899 Bytes
/
load_tasks.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
<?php
include ('db.php');
$conn = db_connect();
$pid = $_GET['pid'];
$q = "select * from tasks where pid=$pid order by due desc, text asc";
$res = mysql_query($q);
$json = queryResultToJSON($res);
echo $json;
db_close($conn);
function queryResultToJSON($res) {
$isFirstObject = true;
$json = "[";
while ($row = mysql_fetch_assoc($res)) {
if (!$isFirstObject) {
$json .= ", ";
}
$isFirstObject = false;
$isFirstKey = true;
$json .= "{";
foreach ($row as $key => $value) {
if (!$isFirstKey) {
$json .= ", ";
}
$isFirstKey = false;
$json .= "\"$key\": ";
if (isQuotedValue($key)) $json .= "\"";
$json .= "$value";
if (isQuotedValue($key)) $json .= "\"";
}
$json .= "}";
}
$json .= "]";
return $json;
}
function isQuotedValue($key) {
return ($key == "text"
|| $key == "due");
}
?>