-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.php
More file actions
43 lines (43 loc) · 1.22 KB
/
index.php
File metadata and controls
43 lines (43 loc) · 1.22 KB
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
<?php
require_once(dirname(__FILE__) . "/makenestedarray.php");
// get query result
$sqlresult = mysql_query("
select g.group,g.groupid,
c.category,c.categoryid,
n.name,n.nameid,n.alias
from groups g
join categories c on g.groupid = c.categoryid
join names n on c.categoryid = n.categoryid
order by g.group,c.category,n.name
");
/*
* define model for nested data
* "key" is required for each level to so that the array filter will work
* "children" should be used for defining nested data
* for other key:val pairs, the "key" should be the column name from the query,
* and the value should be the name of the key you want in the new array
*/
$model = array(
'key'=>'group',
'group'=>'group',
'groupid'=>'groupid',
'children'=>array(
'categories'=>array(
'key'=>'category',
'category'=>'category',
'children'=>array(
'names'=>array(
'key'=>'name',
"nameid"=>"nameid",
"alias"=>"alias"
)
)
)
)
);
// pass sql result and data model to makenestedarray() to retrieve nested result
$data = makenestedarray($sqlresult,$model);
$jsonresult = array("groups" => $data);
// serialize this mug, and return the string
return json_encode($jsonresult);
?>