回答編集履歴
2
修正
test
CHANGED
@@ -23,3 +23,29 @@
|
|
23
23
|
</a>
|
24
24
|
|
25
25
|
```
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
> テーマのみをトップページに新しい順に並べ
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
であればこう
|
34
|
+
|
35
|
+
```php
|
36
|
+
|
37
|
+
$sql ="select post_id,theme from toukou order by post_id desc";
|
38
|
+
|
39
|
+
$stmt = $dbh->query( $sql );
|
40
|
+
|
41
|
+
foreach ($stmt->fetchAll() as $result){
|
42
|
+
|
43
|
+
echo <<<EOF
|
44
|
+
|
45
|
+
<a class="aa" href="detail.php?post_id={$result['post_id']}">theme:{$result['theme']}</a>
|
46
|
+
|
47
|
+
EOF;
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
```
|
1
修正
test
CHANGED
@@ -4,4 +4,22 @@
|
|
4
4
|
|
5
5
|
また、max(post_id)で取得している以上は1件しかデータが取得されないので、fetchAll()である必要はないと思います。
|
6
6
|
|
7
|
+
[fetch()](https://www.php.net/manual/ja/pdostatement.fetch.php)で充分ですね。
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
※構文エラーだけ取り除いた未検証コード
|
12
|
+
|
13
|
+
```php
|
14
|
+
|
15
|
+
$latest_data = $stmt->fetch(FETCH_ASSOC);
|
16
|
+
|
17
|
+
?>
|
18
|
+
|
19
|
+
<a class="aa" href="detail.php?post_id=<?=$latest_data['post_id']?>">
|
20
|
+
|
21
|
+
<?=" theme:". $latest_data['theme']?>
|
22
|
+
|
7
|
-
|
23
|
+
</a>
|
24
|
+
|
25
|
+
```
|