質問編集履歴
1
コードを追記致しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -29,3 +29,73 @@
|
|
29
29
|
|
30
30
|
|
31
31
|
https://m24.hatenablog.com/entry/mysql-hy000
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
コードはこちらで合っていますでしょうか?
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
```php
|
44
|
+
|
45
|
+
<?php
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
$num = 10;
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
$dsn = 'mysql:host=127.0.0.1;dbname=futsal;charset=utf8';
|
54
|
+
|
55
|
+
$user = 'futsaluser';
|
56
|
+
|
57
|
+
$password = 'soccer';
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
$page = 0;
|
62
|
+
|
63
|
+
if (isset($_GET['page']) && $_GET['page'] > 0) {
|
64
|
+
|
65
|
+
$page = intval($_GET['page']) -1;
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
try {
|
72
|
+
|
73
|
+
$db = new PDO($dsn, $user, $password);
|
74
|
+
|
75
|
+
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
76
|
+
|
77
|
+
$stmt = $db->prepare(
|
78
|
+
|
79
|
+
"SELECT * FROM futsal ORDER BY date DESC LIMIT :page, :num"
|
80
|
+
|
81
|
+
);
|
82
|
+
|
83
|
+
$page = $page * $num;
|
84
|
+
|
85
|
+
$stmt->bindParam(':page', $page, PDO::PARAM_INT);
|
86
|
+
|
87
|
+
$stmt->bindParam(':num', $num, PDO::PARAM_INT);
|
88
|
+
|
89
|
+
$stmt->execute();
|
90
|
+
|
91
|
+
} catch(PDOException $e) {
|
92
|
+
|
93
|
+
echo "エラー:" . $e->getMessage();
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
?>
|
100
|
+
|
101
|
+
```
|