How can the fetchAll() function be utilized in PHP to display multiple entries from a table instead of just one?

To display multiple entries from a table using the fetchAll() function in PHP, you need to fetch all the rows returned by a query and then iterate through the results to display each entry. This can be achieved by using a foreach loop to iterate over the array of rows fetched by fetchAll() and display the desired information for each entry.

// Assuming $pdo is your PDO object and $stmt is your prepared statement

$stmt = $pdo->prepare("SELECT * FROM table_name");
$stmt->execute();

$rows = $stmt->fetchAll();

foreach ($rows as $row) {
    echo $row['column_name_1'] . ' - ' . $row['column_name_2'] . '<br>';
}