質問編集履歴

2

モデルのコードとテンプレートのコードの追加、

2019/01/08 02:23

投稿

kazumons
kazumons

スコア15

test CHANGED
File without changes
test CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  画像以外はうまく表示されました。
6
6
 
7
+ モデルに書き換えたことで、画像ファイルに画像が入らなくなったのが原因みたいです。
8
+
7
9
  考えられる理由は何でしょうか?ご回答お願いいたします。
8
10
 
9
11
 

1

modelクラスと実際に表示している画面のコードを載せました

2019/01/08 02:22

投稿

kazumons
kazumons

スコア15

test CHANGED
File without changes
test CHANGED
@@ -117,3 +117,195 @@
117
117
  }
118
118
 
119
119
  ```
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+ 質問追記
128
+
129
+ model/lucks.php
130
+
131
+ ```
132
+
133
+ <?php
134
+
135
+ require_once("../config.php");
136
+
137
+
138
+
139
+ class Luck {
140
+
141
+ private $db;
142
+
143
+ function __construct() {
144
+
145
+ $user = root;
146
+
147
+ $password = root;
148
+
149
+ $dbname = 'luck';
150
+
151
+ $host = 'localhost';
152
+
153
+ $dsn = "mysql:host={$host};dbname={$dbname};charset=utf8";
154
+
155
+ $this->db = new PDO($dsn, $user, $password);
156
+
157
+
158
+
159
+ }
160
+
161
+
162
+
163
+ public function addContent($name){
164
+
165
+ $sql = "INSERT INTO lucks (content) VALUES ('" . $name . "')";
166
+
167
+ error_log("sql=" . $sql);
168
+
169
+ $stm = $this->db->prepare($sql);
170
+
171
+ $stm->execute();
172
+
173
+
174
+
175
+ return $this->db->lastInsertId();
176
+
177
+ }
178
+
179
+
180
+
181
+ public function updateImage($fname){
182
+
183
+ $sql = "UPDATE lucks set attach_filename = '" . $fname . "' WHERE id = ".$id;
184
+
185
+ error_log("sql=" . $sql);
186
+
187
+ $stm = $this->db->prepare($sql);
188
+
189
+ $stm->execute();
190
+
191
+ return $this->db->lastInsertId();
192
+
193
+ }
194
+
195
+
196
+
197
+ public function getLuckByAll($id,$content,$attach_filename,$deleted_at){
198
+
199
+ $sql = "SELECT * FROM lucks";
200
+
201
+ error_log("sql=" . $sql);
202
+
203
+ $stm = $this->db->prepare($sql);
204
+
205
+ $stm->execute();
206
+
207
+ $record_list = $stm->fetchAll();
208
+
209
+ return $record_list;
210
+
211
+ }
212
+
213
+ }
214
+
215
+
216
+
217
+ ```
218
+
219
+
220
+
221
+
222
+
223
+ 画像を表示しているページ
224
+
225
+ (index.tpl)
226
+
227
+
228
+
229
+ ```
230
+
231
+ <!DOCTYPE html>
232
+
233
+ <html>
234
+
235
+ <head>
236
+
237
+ <title>a</title>
238
+
239
+ <meta charset="utf-8">
240
+
241
+ </head>
242
+
243
+ <body>
244
+
245
+ <table border='1'>
246
+
247
+ <tr>
248
+
249
+ <td>内容</td>
250
+
251
+ <tr>
252
+
253
+ {foreach from=$indexdata item=current}
254
+
255
+ <td>{$current.id}</td>
256
+
257
+ <td>{$current.content}</td>
258
+
259
+
260
+
261
+
262
+
263
+ {if $current.attach_filename}
264
+
265
+
266
+
267
+ <td><img src='/luckfile/images/{$current.attach_filename}'/></td>
268
+
269
+
270
+
271
+ {else}
272
+
273
+ <td>no image</td>
274
+
275
+ {/if}
276
+
277
+
278
+
279
+
280
+
281
+ <td><form method="POST" action="delete.php">
282
+
283
+ <input type="hidden" name="id" value='{$current.id}'>
284
+
285
+ <input type="submit" value="削除"></form></td>
286
+
287
+ <td>
288
+
289
+ <a href="/luckfile/edit_menu.php?id={$current.id}">編集</a>
290
+
291
+ </td>
292
+
293
+ <td>
294
+
295
+ <a href="/luckfile/show.php?id={$current.id}">詳細</a>
296
+
297
+ </td>
298
+
299
+ </tr>
300
+
301
+ {/foreach}
302
+
303
+ </table>
304
+
305
+ </body>
306
+
307
+ </html>
308
+
309
+
310
+
311
+ ```