-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcourseList_old.php
56 lines (43 loc) · 1.26 KB
/
courseList_old.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
<?php
/**
* @author Chris Rehfeld
*/
header('content-type: application/json;charset=utf-8');
//header('content-type: text/plain;charset=utf-8');
require_once 'connection.php';
$sql = "
select site, category, title, course_link from course_data
";
$result = $dbc->query($sql);
$rows = array();
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
}
$groups = array();
foreach ($rows as $row) {
extract($row);
$letter = mb_strtolower(mb_substr($title, 0, 1, 'utf-8'), 'utf-8');
$groups[$letter][$site][$category][] = $row;
}
function toD3Structure($arr) {
//check if it has numeric keys
//non-numeric means titles and names etc...
//assume first key represents all the keys types
if (is_numeric(key($arr))) {
$ret = array();
foreach ($arr as $subArr) {
//$ret[] = array('name' => $subArr['title']);
$ret[] = $subArr + array('name' => $subArr['title'], 'size' => 2);
}
return $ret;
}
$ret = array();
foreach ($arr as $key => $subArr) {
$ret[] = array('name' => $key, 'children' => toD3Structure($subArr));
}
return $ret;
}
$dataGroupedByLetters = array_map('toD3Structure', $groups);
//print_r($dataGroupedByLetters);
echo json_encode($dataGroupedByLetters);
?>