質問編集履歴

1

変更点をのせました

2019/04/12 05:29

投稿

sorata_toll
sorata_toll

スコア19

test CHANGED
File without changes
test CHANGED
@@ -199,3 +199,201 @@
199
199
 
200
200
 
201
201
  ```
202
+
203
+
204
+
205
+ #変更後
206
+
207
+ ```PHP
208
+
209
+ <?php
210
+
211
+ require('connect.php');
212
+
213
+ $page = $_REQUEST['page'];
214
+
215
+ if ($page == '') {
216
+
217
+ $page = 1;
218
+
219
+ }
220
+
221
+ $page = max($page, 1);
222
+
223
+
224
+
225
+ // 最終ページを取得する
226
+
227
+ $sql = 'SELECT COUNT(*) AS cnt FROM my_items';
228
+
229
+ $recordSet = mysqli_query($db,$sql);
230
+
231
+ $table = mysqli_fetch_assoc($db,$recordSet);
232
+
233
+ $maxPage = ceil($table['cnt'] / 5);
234
+
235
+ $page = min($page, $maxPage);
236
+
237
+
238
+
239
+ $start = ($page - 1) * 5;
240
+
241
+
242
+
243
+ $recordSet = mysqli_query($db,'SELECT m.name, i.* FROM maker m, my_items i WHERE m.id=i.maker_id ORDER BY id DESC LIMIT ' . $start . ',5');
244
+
245
+ ?>
246
+
247
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
248
+
249
+ <html xmlns="http://www.w3.org/1999/xhtml">
250
+
251
+ <head>
252
+
253
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
254
+
255
+ <link rel="stylesheet" type="text/css" href="style.css" />
256
+
257
+ <title>商品管理</title>
258
+
259
+ </head>
260
+
261
+
262
+
263
+ <body>
264
+
265
+ <div id="wrap">
266
+
267
+ <div id="head">
268
+
269
+ <h1>商品管理</h1>
270
+
271
+ </div>
272
+
273
+
274
+
275
+ <div id="content">
276
+
277
+ <table width="100%">
278
+
279
+ <tr>
280
+
281
+ <th scope="col">ID</th>
282
+
283
+ <th scope="col">メーカー</th>
284
+
285
+ <th scope="col">商品名</th>
286
+
287
+ <th scope="col">価格</th>
288
+
289
+ </tr>
290
+
291
+ <?php
292
+
293
+ while ($table = mysqli_fetch_assoc($recordSet)) {
294
+
295
+ ?>
296
+
297
+ <tr>
298
+
299
+ <td><?php print(htmlspecialchars($table['id'])); ?></td>
300
+
301
+ <td><?php print(htmlspecialchars($table['maker_id'])); ?></td>
302
+
303
+ <td><?php print(htmlspecialchars($table['item_name'])); ?></td>
304
+
305
+ <td><?php print(htmlspecialchars($table['price'])); ?></td>
306
+
307
+ </tr>
308
+
309
+ <?php
310
+
311
+ }
312
+
313
+ ?>
314
+
315
+ </table>
316
+
317
+
318
+
319
+ <ul class="paging">
320
+
321
+ <?php
322
+
323
+ if ($page > 1) {
324
+
325
+ ?>
326
+
327
+ <li><a href="index.php?page=<?php print($page - 1); ?>">前のページへ</a></li>
328
+
329
+ <?php
330
+
331
+ } else {
332
+
333
+ ?>
334
+
335
+ <li>前のページへ</li>
336
+
337
+ <?php
338
+
339
+ }
340
+
341
+ ?>
342
+
343
+ <?php
344
+
345
+ if ($page < $maxPage) {
346
+
347
+ ?>
348
+
349
+ <li><a href="index.php?page=<?php print($page + 1); ?>">次のページへ</a></li>
350
+
351
+ <?php
352
+
353
+ } else {
354
+
355
+ ?>
356
+
357
+ <li>次のページへ</li>
358
+
359
+ <?php
360
+
361
+ }
362
+
363
+ ?>
364
+
365
+ </ul>
366
+
367
+
368
+
369
+ </div>
370
+
371
+
372
+
373
+ <div id="foot">
374
+
375
+ <p><img src="images/txt_copyright.png" width="136" height="15" alt="(C) H2O Space. MYCOM" /></p>
376
+
377
+ </div>
378
+
379
+
380
+
381
+ </div>
382
+
383
+ </body>
384
+
385
+ </html>
386
+
387
+
388
+
389
+ ```
390
+
391
+ 43行目が
392
+
393
+ while ($table = mysqli_fetch_assoc($recordSet)) {
394
+
395
+ になってます
396
+
397
+ #変更後のエラー
398
+
399
+ Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\index.php on line 43