fetch()
function returns you the next row from the result set. You need something like this to get all results:
while($data = $sql->fetch()) {
echo ($data['author']);
echo ($data['date']);
//...etc...
}
Or you can use fetchAll()
function which returns an array with each row from the result and you can use a loop top traverse the array and do whatever you want with each row.
Example with fetchAll()
:
$data = $sql->fetchAll(PDO::FETCH_ASSOC);
foreach($data as $row) {
echo $row['autor'];
echo $row['date'];
//do whatever you want with the row
}