質問編集履歴
4
解決
title
CHANGED
File without changes
|
body
CHANGED
@@ -100,4 +100,10 @@
|
|
100
100
|
["id"] => string(5)"20161"
|
101
101
|
}
|
102
102
|
```
|
103
|
-
一行分だけ書きましたが、このような形になっておりました。
|
103
|
+
一行分だけ書きましたが、このような形になっておりました。
|
104
|
+
|
105
|
+
###解決
|
106
|
+
今回はコード云々ではなくDB側の設計ミスでした。。。
|
107
|
+
plan_insert側では一行だけですので、plan_idを主キーにしていて問題は無かったのですが、、、当然な話ですね。
|
108
|
+
staff_insert側も同じようにplan_idを主キーにしていたのが原因でした。
|
109
|
+
別に主キー用のidを追加して、行ってみたら普通にできました。
|
3
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -31,10 +31,12 @@
|
|
31
31
|
$staff = $plan[$i]['staff'];
|
32
32
|
if ($staff != "") {
|
33
33
|
$staff_insert = staff_insert($id, $staff);
|
34
|
-
|
34
|
+
}
|
35
|
+
}
|
35
36
|
$time = $plan['time'];
|
36
37
|
$plan_insert = plan_insert($id, $name, $time);
|
37
38
|
}
|
39
|
+
}
|
38
40
|
```
|
39
41
|
いろいろ、書き方が初心者丸出しですが、、、とりあえずこのように書きました。
|
40
42
|
```PHP
|
2
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -25,19 +25,15 @@
|
|
25
25
|
$plans = $_POST['plan'];
|
26
26
|
foreach($plans as $plan) {
|
27
27
|
$name = $plan['name'];
|
28
|
-
if ($name =
|
28
|
+
if ($name != "") {
|
29
|
-
|
30
|
-
} else {
|
31
|
-
|
29
|
+
$id = $plan['id'];
|
32
|
-
|
30
|
+
for ($i = 0; $i < 3; $i++) {
|
33
|
-
|
31
|
+
$staff = $plan[$i]['staff'];
|
34
|
-
|
32
|
+
if ($staff != "") {
|
35
|
-
|
36
|
-
} else {
|
37
|
-
|
33
|
+
$staff_insert = staff_insert($id, $staff);
|
38
|
-
|
34
|
+
}
|
39
|
-
|
35
|
+
$time = $plan['time'];
|
40
|
-
|
36
|
+
$plan_insert = plan_insert($id, $name, $time);
|
41
37
|
}
|
42
38
|
```
|
43
39
|
いろいろ、書き方が初心者丸出しですが、、、とりあえずこのように書きました。
|
1
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,15 +7,15 @@
|
|
7
7
|
```HTML
|
8
8
|
<!-- 実際のコードだと長いので、簡単に記述します -->
|
9
9
|
<form action="" method="POST">
|
10
|
-
<?php for ($i = 1; $i <= 8; $i++) : ?>
|
10
|
+
<?php for ($i = 1; $i <= 8; $i++) : ?>
|
11
|
-
1.訪問先:<input type="text" name="plan[<?= $i; ?>][name]">
|
11
|
+
1.訪問先:<input type="text" name="plan[<?= $i; ?>][name]">
|
12
|
-
2.訪問時間:<input type="text" name="plan[<?= $i; ?>][time]">
|
12
|
+
2.訪問時間:<input type="text" name="plan[<?= $i; ?>][time]">
|
13
|
-
<?php for ($j = 0; $j < 3; $j++) : ?>
|
13
|
+
<?php for ($j = 0; $j < 3; $j++) : ?>
|
14
|
-
3.訪問スタッフ<?= $j; ?>:<input type="text" name="plan[<?= $i; ?>][<?= $j; ?>][staff]";
|
14
|
+
3.訪問スタッフ<?= $j; ?>:<input type="text" name="plan[<?= $i; ?>][<?= $j; ?>][staff]";
|
15
|
-
<?php endfor; ?>
|
15
|
+
<?php endfor; ?>
|
16
|
-
<input type="hidden" name="plan[<?= $i; ?>][id]" value="2016<?= $i; ?>">
|
16
|
+
<input type="hidden" name="plan[<?= $i; ?>][id]" value="2016<?= $i; ?>">
|
17
|
-
<?php endfor; ?>
|
17
|
+
<?php endfor; ?>
|
18
|
-
<input type="submit" name="submit">
|
18
|
+
<input type="submit" name="submit">
|
19
19
|
</form>
|
20
20
|
```
|
21
21
|
とりあえず、上記のようにしました。
|
@@ -24,32 +24,32 @@
|
|
24
24
|
```PHP
|
25
25
|
$plans = $_POST['plan'];
|
26
26
|
foreach($plans as $plan) {
|
27
|
-
$name = $plan['name'];
|
27
|
+
$name = $plan['name'];
|
28
|
-
if ($name == "") {
|
28
|
+
if ($name == "") {
|
29
29
|
|
30
|
-
} else {
|
30
|
+
} else {
|
31
|
-
$id = $plan['id'];
|
31
|
+
$id = $plan['id'];
|
32
|
-
for ($i = 0; $i < 3; $i++) {
|
32
|
+
for ($i = 0; $i < 3; $i++) {
|
33
|
-
$staff = $plan[$i]['staff'];
|
33
|
+
$staff = $plan[$i]['staff'];
|
34
|
-
if ($staff == "") {
|
34
|
+
if ($staff == "") {
|
35
35
|
|
36
|
-
} else {
|
36
|
+
} else {
|
37
|
-
$staff_insert = staff_insert($id, $staff);
|
37
|
+
$staff_insert = staff_insert($id, $staff);
|
38
|
-
}
|
38
|
+
}
|
39
|
-
$time = $plan['time'];
|
39
|
+
$time = $plan['time'];
|
40
|
-
$plan_insert = plan_insert($id, $name, $time);
|
40
|
+
$plan_insert = plan_insert($id, $name, $time);
|
41
|
-
}
|
41
|
+
}
|
42
42
|
```
|
43
43
|
いろいろ、書き方が初心者丸出しですが、、、とりあえずこのように書きました。
|
44
44
|
```PHP
|
45
45
|
function staff_insert($id, $staff) {
|
46
46
|
// DB接続
|
47
|
-
$sql = "INSERT INTO plan_staff (plan_id, staff) VALUES (:id, :staff)";
|
47
|
+
$sql = "INSERT INTO plan_staff (plan_id, staff) VALUES (:id, :staff)";
|
48
|
-
$stmt = $dbh->prepare($sql);
|
48
|
+
$stmt = $dbh->prepare($sql);
|
49
|
-
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
|
49
|
+
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
|
50
|
-
$stmt->bindParam(':staff', $staff, PDO::PARAM_STR);
|
50
|
+
$stmt->bindParam(':staff', $staff, PDO::PARAM_STR);
|
51
|
-
$stmt->execute();
|
51
|
+
$stmt->execute();
|
52
|
-
return $staff_insert;
|
52
|
+
return $staff_insert;
|
53
53
|
}
|
54
54
|
|
55
55
|
function plan_insert($id, $name, $time) {
|
@@ -80,4 +80,26 @@
|
|
80
80
|
|
81
81
|
登録とかよりechoしてみると、値は表示されてくるのですが、、、、
|
82
82
|
|
83
|
-
この辺り初歩的な部分かと思いますが、アドバイスお願いできますでしょうか?
|
83
|
+
この辺り初歩的な部分かと思いますが、アドバイスお願いできますでしょうか?
|
84
|
+
|
85
|
+
###修正と追記
|
86
|
+
ご指摘ありがとうございます。コードに関してはインデントをしてみました。
|
87
|
+
var_dumpの結果を表示いたします。
|
88
|
+
```
|
89
|
+
array(8) {
|
90
|
+
[1] => array(6) {
|
91
|
+
["name"] => string(3)"AAA"
|
92
|
+
["time"] => string(5)"12:30"
|
93
|
+
[0] => array(1) {
|
94
|
+
["staff"] => string(1)"A"
|
95
|
+
}
|
96
|
+
[1] => array(1) {
|
97
|
+
["staff"] => string(1)"B"
|
98
|
+
}
|
99
|
+
[2] => array(1) {
|
100
|
+
["staff"] => string(1)"C"
|
101
|
+
}
|
102
|
+
["id"] => string(5)"20161"
|
103
|
+
}
|
104
|
+
```
|
105
|
+
一行分だけ書きましたが、このような形になっておりました。
|