fetch+while
fetchは一件だけ取得するとそこで処理が終わる。whileでそれを繰り返すことで一覧表示できる。
while ($user = $users->fetch(PDO::FETCH_ASSOC)) : ?>
<div class="msg">
<img src="<?php print(htmlspecialchars($user['picture'])); ?>" />
<p><span class="name"><?php print(htmlspecialchars($user['title'])); ?>です</span></p>
</div>
<?php endwhile; ?>
fetchAll+foreach
fetchAllでデータを全件取得してそれを配列にまとめるので、その配列化したものをforeachで1件ずつ表示する。
$users = $users->fetchAll(PDO::FETCH_ASSOC);
foreach ($users as $user) : ?>
<img src="<?php print(htmlspecialchars($user['picture'])); ?>" />
<p><span class="name"><?php print(htmlspecialchars($user['title'])); ?>です</span></p>
<br>
<?php endforeach ?>