質問編集履歴
5
実施したコードの記載
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,15 +14,31 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
|
17
|
-
|
17
|
+
### 取り出すために実施したこと
|
18
18
|
|
19
|
-
js
|
19
|
+
```javascript
|
20
|
+
|
21
|
+
for (var key in b_options) {
|
22
|
+
|
23
|
+
console.log(b_options);
|
24
|
+
|
25
|
+
console.log("b_options[key].code");
|
26
|
+
|
27
|
+
console.log("b_options[key].name");
|
28
|
+
|
29
|
+
}
|
20
30
|
|
21
31
|
|
22
32
|
|
23
|
-
|
33
|
+
//出力結果
|
34
|
+
|
35
|
+
var b_options =[[{"code":"001","name":"営業A"},{"code":"002","name":"営業B"},{"code":"003","name":"営業C"},{"code":"004","name":"開発"}],[{"code":"001","name":"営業A"},{"code":"002","name":"営業B"},{"code":"003","name":"開発"}],
|
24
36
|
|
25
37
|
[{"code":"001","name":"営業A",{"code":"002","name":"営業B"},{"code":"003","name":"開発A"},{"code":"004","name":"開発B"}]]
|
38
|
+
|
39
|
+
undefined
|
40
|
+
|
41
|
+
undefined
|
26
42
|
|
27
43
|
```
|
28
44
|
|
4
タイトルの変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
json形式のデータの取り出し方
|
test
CHANGED
File without changes
|
3
文書の入れ替え
test
CHANGED
File without changes
|
test
CHANGED
@@ -11,6 +11,20 @@
|
|
11
11
|
|
12
12
|
|
13
13
|
valueの値をjson形式で取得したデータよりセットしようと試みましたが、以下の連想配列より'code'もしくは'name'部分のみ取り出す方法が分かりません。
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
```
|
18
|
+
|
19
|
+
json形式で取得したデータ
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
[[{"code":"001","name":"営業A"},{"code":"002","name":"営業B"},{"code":"003","name":"営業C"},{"code":"004","name":"開発"}],[{"code":"001","name":"営業A"},{"code":"002","name":"営業B"},{"code":"003","name":"開発"}],
|
24
|
+
|
25
|
+
[{"code":"001","name":"営業A",{"code":"002","name":"営業B"},{"code":"003","name":"開発A"},{"code":"004","name":"開発B"}]]
|
26
|
+
|
27
|
+
```
|
14
28
|
|
15
29
|
|
16
30
|
|
@@ -34,17 +48,7 @@
|
|
34
48
|
|
35
49
|
|
36
50
|
|
37
|
-
```
|
38
51
|
|
39
|
-
json形式で取得したデータ
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
[[{"code":"001","name":"営業A"},{"code":"002","name":"営業B"},{"code":"003","name":"営業C"},{"code":"004","name":"開発"}],[{"code":"001","name":"営業A"},{"code":"002","name":"営業B"},{"code":"003","name":"開発"}],
|
44
|
-
|
45
|
-
[{"code":"001","name":"営業A",{"code":"002","name":"営業B"},{"code":"003","name":"開発A"},{"code":"004","name":"開発B"}]]
|
46
|
-
|
47
|
-
```
|
48
52
|
|
49
53
|
### 現在の完成したコード
|
50
54
|
|
2
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,7 +34,9 @@
|
|
34
34
|
|
35
35
|
|
36
36
|
|
37
|
+
```
|
38
|
+
|
37
|
-
|
39
|
+
json形式で取得したデータ
|
38
40
|
|
39
41
|
|
40
42
|
|
1
①必要なコードのみ表示②現在の配列を表示③実現したい完成形を表示
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,35 +10,37 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
-
しかし、私が作成したもののままだとvalueの値は自動的に0から数字が割り当てられたものがセットされています。
|
14
|
-
|
15
|
-
|
13
|
+
valueの値をjson形式で取得したデータよりセットしようと試みましたが、以下の連想配列より'code'もしくは'name'部分のみ取り出す方法が分かりません。
|
16
14
|
|
17
15
|
|
18
16
|
|
17
|
+
最終的には以下のような表示を実現したいです。
|
18
|
+
|
19
|
+
```html
|
20
|
+
|
21
|
+
<select id="select_a">東日本</select>
|
22
|
+
|
19
|
-
|
23
|
+
<select id="select_b">
|
24
|
+
|
25
|
+
<option value="001">営業A</option>
|
26
|
+
|
27
|
+
<option value="002">営業B</option>
|
28
|
+
|
29
|
+
<option value="003">開発</option>
|
30
|
+
|
31
|
+
</select>
|
32
|
+
|
33
|
+
```
|
20
34
|
|
21
35
|
|
22
36
|
|
23
|
-
|
37
|
+
```json形式で取得したデータ
|
24
38
|
|
25
|
-
```php
|
26
39
|
|
27
|
-
$sqla ="select code,name from amas";
|
28
40
|
|
29
|
-
|
41
|
+
[[{"code":"001","name":"営業A"},{"code":"002","name":"営業B"},{"code":"003","name":"営業C"},{"code":"004","name":"開発"}],[{"code":"001","name":"営業A"},{"code":"002","name":"営業B"},{"code":"003","name":"開発"}],
|
30
42
|
|
31
|
-
|
32
|
-
|
33
|
-
```
|
34
|
-
|
35
|
-
②codeとnameの値をもった配列となる
|
36
|
-
|
37
|
-
```json
|
38
|
-
|
39
|
-
print($json)の結果
|
40
|
-
|
41
|
-
[[{"code":"001","name":"営業A"},{"code":"002","name":"営業B"},{"code":"003","name":"営業C"},{"code":"004","name":"開発"}],[{"code":"001","name":"営業A"},{"code":"002","name":"営業B"},{"code":"003","name":"開発"}],[{"code":"001","name":"営業A"},{"code":"002","name":"営業B"},{"code":"003","name":"開発A"},{"code":"004","name":"開発B"}]]
|
43
|
+
[{"code":"001","name":"営業A",{"code":"002","name":"営業B"},{"code":"003","name":"開発A"},{"code":"004","name":"開発B"}]]
|
42
44
|
|
43
45
|
```
|
44
46
|
|
@@ -66,9 +68,9 @@
|
|
66
68
|
|
67
69
|
<body>
|
68
70
|
|
69
|
-
<select id="select_a"></select>
|
71
|
+
<select id="select_a"></select>
|
70
72
|
|
71
|
-
<select id="select_b"></select>
|
73
|
+
<select id="select_b"></select>
|
72
74
|
|
73
75
|
</body>
|
74
76
|
|
@@ -76,59 +78,7 @@
|
|
76
78
|
|
77
79
|
```
|
78
80
|
|
79
|
-
### php
|
80
81
|
|
81
|
-
|
82
|
-
|
83
|
-
```ここに言語名を入力
|
84
|
-
|
85
|
-
//マスタAの配列を作成
|
86
|
-
|
87
|
-
$sqla ="select name from amas";
|
88
|
-
|
89
|
-
$resta = $pdo->query($sqla);
|
90
|
-
|
91
|
-
$masa = $resta->fetchAll(PDO::FETCH_COLUMN);
|
92
|
-
|
93
|
-
//マスタBの配列を作成
|
94
|
-
|
95
|
-
$sqlb = "select name from bmas";
|
96
|
-
|
97
|
-
$restb = $pdo->query($sqlb);
|
98
|
-
|
99
|
-
$masb = $restb->fetchAll(PDO::FETCH_COLUMN);
|
100
|
-
|
101
|
-
//マスタCの配列を作成
|
102
|
-
|
103
|
-
$sqlc = "select name from cmas";
|
104
|
-
|
105
|
-
$restc = $pdo->query($sqlc);
|
106
|
-
|
107
|
-
$masc = $restc->fetchAll(PDO::FETCH_COLUMN);
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
//空の配列を作成しABCを多重配列の形にまとめる
|
114
|
-
|
115
|
-
$masters = array();
|
116
|
-
|
117
|
-
array_push($masters, $masj);
|
118
|
-
|
119
|
-
array_push($masters, $masr);
|
120
|
-
|
121
|
-
array_push($masters, $masg);
|
122
|
-
|
123
|
-
//json形式に変換
|
124
|
-
|
125
|
-
$json = json_encode($masters,JSON_UNESCAPED_UNICODE);
|
126
|
-
|
127
|
-
print($json);
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
```
|
132
82
|
|
133
83
|
```javascript
|
134
84
|
|
@@ -203,13 +153,3 @@
|
|
203
153
|
});
|
204
154
|
|
205
155
|
```
|
206
|
-
|
207
|
-
```json
|
208
|
-
|
209
|
-
print($json)の結果
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
[["営業A","営業B","営業C","開発"],["営業A","営業B","開発"],[["営業A","営業B","開発A","開発B"]]
|
214
|
-
|
215
|
-
```
|