回答編集履歴
2
2
answer
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
$default = array('id'=>'','year'=>'','month'=>'','day'=>'','content'=>'');
|
12
12
|
$plans = get_csv_plans(); // CSV 読み込み
|
13
13
|
if (isset($_POST['submit'])) {
|
14
|
-
$plans = plan_edit($
|
14
|
+
$plans = plan_edit($plans, $_POST); //データ登録or修正
|
15
15
|
put_csv_data($plans);
|
16
16
|
}
|
17
17
|
if (isset($_GET['action'])) {
|
1
1
answer
CHANGED
@@ -1,3 +1,30 @@
|
|
1
1
|
$output_str に既存のCSV内容を保存したのち、
|
2
2
|
内容を変更せずにCSV出力しているので、
|
3
|
-
実行前後でなにもかわらないってことですね。
|
3
|
+
実行前後でなにもかわらないってことですね。
|
4
|
+
--- 追記 ---
|
5
|
+
コードをべた書きでだーって書いてると読みづらいし
|
6
|
+
理解しにくいし、デバッグも大変ですよね。
|
7
|
+
関数に機能を小分けにするといいです。
|
8
|
+
たとえば。こんな感じ
|
9
|
+
```php
|
10
|
+
<?php
|
11
|
+
$default = array('id'=>'','year'=>'','month'=>'','day'=>'','content'=>'');
|
12
|
+
$plans = get_csv_plans(); // CSV 読み込み
|
13
|
+
if (isset($_POST['submit'])) {
|
14
|
+
$plans = plan_edit($plan, $_POST); //データ登録or修正
|
15
|
+
put_csv_data($plans);
|
16
|
+
}
|
17
|
+
if (isset($_GET['action'])) {
|
18
|
+
$act = $_GET['action'];
|
19
|
+
$id = $_GET['id'];
|
20
|
+
if ($act == 'edit') { //編集指示
|
21
|
+
$default = get_info($plans, $id); //inputタグに表示する内容をセット
|
22
|
+
} else { // 削除指示
|
23
|
+
$plans = plan_delete($plans, $id); //削除
|
24
|
+
put_csv_plans($plans);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
//以下、関数の定義
|
28
|
+
?>
|
29
|
+
//以下HTML部分
|
30
|
+
```
|