質問編集履歴

4

コード

2018/06/23 13:08

投稿

uep3vjz9wp
test CHANGED
File without changes
test CHANGED
@@ -116,6 +116,8 @@
116
116
 
117
117
 
118
118
 
119
+
120
+
119
121
    以上、タグ
120
122
 
121
123
 

3

コード

2018/06/23 13:06

投稿

uep3vjz9wp
test CHANGED
File without changes
test CHANGED
@@ -30,7 +30,7 @@
30
30
 
31
31
 
32
32
 
33
- <!DOCTYPE html>
33
+ ```<!DOCTYPE html>
34
34
 
35
35
  <html lang="ja">
36
36
 
@@ -112,7 +112,7 @@
112
112
 
113
113
  }
114
114
 
115
- ?>
115
+ ?>```
116
116
 
117
117
 
118
118
 

2

コード

2018/06/23 13:06

投稿

uep3vjz9wp
test CHANGED
File without changes
test CHANGED
@@ -26,6 +26,52 @@
26
26
 
27
27
 
28
28
 
29
+   以下タグ
30
+
31
+
32
+
33
+ <!DOCTYPE html>
34
+
35
+ <html lang="ja">
36
+
37
+ <head>
38
+
39
+ <meta charset="UTF-8">
40
+
41
+ <title>データ一覧</title>
42
+
43
+ </head>
44
+
45
+ <body>
46
+
47
+ <h1>2018年 データ一覧</h1>
48
+
49
+ <a href="form.html">データ新規登録</a>
50
+
51
+ <?php
52
+
53
+ require_once 'db_config.php';
54
+
55
+ try {
56
+
57
+ $dbh = new PDO('mysql:host=localhost;dbname=data_db1;charset=utf8', $user, $pass);
58
+
59
+ $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
60
+
61
+ $sql = "SELECT * FROM table_data";
62
+
63
+ $stmt = $dbh->query($sql);
64
+
65
+ $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
66
+
67
+ echo "<table>\n";
68
+
69
+ echo "<tr>\n";
70
+
71
+ echo "<th>月</th><th>日</th><th>カテゴリ</th>\n";
72
+
73
+ echo "</tr>\n";
74
+
29
75
  foreach ($result as $row) {
30
76
 
31
77
  echo "<tr>\n";
@@ -35,6 +81,42 @@
35
81
  echo "<td>" . htmlspecialchars($row['day'],ENT_QUOTES,'UTF-8') . "</td>\n";
36
82
 
37
83
  echo "<td>" . htmlspecialchars($row['category'],ENT_QUOTES,'UTF-8') . "</td>\n";
84
+
85
+
86
+
87
+ echo "<td>\n";
88
+
89
+ echo "|<a href=edit.php?id=" . htmlspecialchars($row['id'],ENT_QUOTES,'UTF-8') . ">変更</a>\n";
90
+
91
+ echo "|<a href=delete.php?id=" . htmlspecialchars($row['id'],ENT_QUOTES,'UTF-8') . ">削除</a>\n";
92
+
93
+ echo "</td>\n";
94
+
95
+
96
+
97
+
98
+
99
+ echo "</tr>\n";
100
+
101
+ }
102
+
103
+ echo "</table>\n";
104
+
105
+ $dbh = null;
106
+
107
+ } catch (PDOException $e) {
108
+
109
+ echo "エラー発生: " . htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8') . "<br>";
110
+
111
+ die();
112
+
113
+ }
114
+
115
+ ?>
116
+
117
+
118
+
119
+   以上、タグ
38
120
 
39
121
 
40
122
 

1

より詳しく記入しました。

2018/06/23 08:03

投稿

uep3vjz9wp
test CHANGED
File without changes
test CHANGED
@@ -26,50 +26,6 @@
26
26
 
27
27
 
28
28
 
29
- ```php
30
-
31
- <!DOCTYPE html>
32
-
33
- <html lang="ja">
34
-
35
- <head>
36
-
37
- <meta charset="UTF-8">
38
-
39
- <title>データ一覧</title>
40
-
41
- </head>
42
-
43
- <body>
44
-
45
- <h1>2018年 データ一覧</h1>
46
-
47
- <a href="form.html">データ新規登録</a>
48
-
49
- <?php
50
-
51
- require_once 'db_config.php';
52
-
53
- try {
54
-
55
- $dbh = new PDO('mysql:host=localhost;dbname=data_db1;charset=utf8', $user, $pass);
56
-
57
- $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
58
-
59
- $sql = "SELECT * FROM table_data";
60
-
61
- $stmt = $dbh->query($sql);
62
-
63
- $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
64
-
65
- echo "<table>\n";
66
-
67
- echo "<tr>\n";
68
-
69
- echo "<th>月</th><th>日</th><th>カテゴリ</th>\n";
70
-
71
- echo "</tr>\n";
72
-
73
29
  foreach ($result as $row) {
74
30
 
75
31
  echo "<tr>\n";
@@ -82,49 +38,11 @@
82
38
 
83
39
 
84
40
 
85
- echo "<td>\n";
86
-
87
- echo "|<a href=edit.php?id=" . htmlspecialchars($row['id'],ENT_QUOTES,'UTF-8') . ">変更</a>\n";
88
-
89
- echo "|<a href=delete.php?id=" . htmlspecialchars($row['id'],ENT_QUOTES,'UTF-8') . ">削除</a>\n";
90
-
91
- echo "</td>\n";
92
-
93
-
94
-
95
-
96
-
97
- echo "</tr>\n";
98
-
99
- }
100
-
101
- echo "</table>\n";
102
-
103
- $dbh = null;
104
-
105
- } catch (PDOException $e) {
106
-
107
- echo "エラー発生: " . htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8') . "<br>";
108
-
109
- die();
110
-
111
- }
112
-
113
- ?>
114
-
115
- ```
116
-
117
-
118
-
119
-
120
-
121
41
 
122
42
 
123
43
 
124
44
 
125
45
   下記のようなif文を使うのでしょうか?
126
-
127
- ```php
128
46
 
129
47
  if ($_POST['category'] === '1') echo "いちばん";
130
48
 
@@ -133,8 +51,6 @@
133
51
  if ($_POST['category'] === '3') echo "さんばん";
134
52
 
135
53
  if ($_POST['category'] === '4') echo "よんばん";
136
-
137
- ```
138
54
 
139
55
 
140
56