回答編集履歴
1
sample
answer
CHANGED
@@ -1,4 +1,58 @@
|
|
1
1
|
おそらくCONCATはしないほうがいいと思います
|
2
2
|
RDBからの戻りはassocでfetchAllすればスプレッドシート的な
|
3
3
|
縦×横のデータになるので、組み替えてからjsonエンコードするだけです
|
4
|
-
組み換えについては元データと結果の提示がないのでなんとも言えません
|
4
|
+
組み換えについては元データと結果の提示がないのでなんとも言えません
|
5
|
+
|
6
|
+
# sample
|
7
|
+
|
8
|
+
```PHP
|
9
|
+
/*$aはfetchAllするものとします*/
|
10
|
+
$a=[
|
11
|
+
[
|
12
|
+
"type"=>"t_1",
|
13
|
+
"properties01"=>"p1_1",
|
14
|
+
"properties02"=>"p2_1",
|
15
|
+
"material01_shop01"=>"m1s1_1",
|
16
|
+
"material01_shop02"=>"m1s2_1",
|
17
|
+
"material02_shop01"=>"m2s1_1",
|
18
|
+
"material02_shop02"=>"m2s2_1",
|
19
|
+
"id"=>"i_1",
|
20
|
+
],
|
21
|
+
[
|
22
|
+
"type"=>"t_2",
|
23
|
+
"properties01"=>"p1_2",
|
24
|
+
"properties02"=>"p2_2",
|
25
|
+
"material01_shop01"=>"m1s1_2",
|
26
|
+
"material01_shop02"=>"m1s2_2",
|
27
|
+
"material02_shop01"=>"m2s1_2",
|
28
|
+
"material02_shop02"=>"m2s2_2",
|
29
|
+
"id"=>"i_2",
|
30
|
+
],
|
31
|
+
[
|
32
|
+
"type"=>"t_3",
|
33
|
+
"properties01"=>"p1_3",
|
34
|
+
"properties02"=>"p2_3",
|
35
|
+
"material01_shop01"=>"m1s1_3",
|
36
|
+
"material01_shop02"=>"m1s2_3",
|
37
|
+
"material02_shop01"=>"m2s1_3",
|
38
|
+
"material02_shop02"=>"m2s2_3",
|
39
|
+
"id"=>"i_3",
|
40
|
+
],
|
41
|
+
];
|
42
|
+
$b=[];
|
43
|
+
foreach($a as $key=>$val){
|
44
|
+
$b[$key]["type"]=$val["type"];
|
45
|
+
$b[$key]["properties"]=[];/*空配列は宣言しなくてもOKだが念の為*/
|
46
|
+
$b[$key]["properties"]["properties01"]=$val["properties01"];
|
47
|
+
$b[$key]["properties"]["properties02"]=$val["properties02"];
|
48
|
+
$b[$key]["material"]=[];
|
49
|
+
$b[$key]["material"]["material01"]=[];
|
50
|
+
$b[$key]["material"]["material01"]["material01_shop01"]=$val["material01_shop01"];
|
51
|
+
$b[$key]["material"]["material01"]["material01_shop02"]=$val["material01_shop02"];
|
52
|
+
$b[$key]["material"]["material02"]=[];
|
53
|
+
$b[$key]["material"]["material02"]["material02_shop01"]=$val["material02_shop01"];
|
54
|
+
$b[$key]["material"]["material02"]["material02_shop02"]=$val["material02_shop02"];
|
55
|
+
$b[$key]["idl"]=$val["id"];
|
56
|
+
}
|
57
|
+
print_r(json_encode($b, JSON_PRETTY_PRINT));
|
58
|
+
```
|