When implementing pagination in PHP for displaying database results, what are some common pitfalls to avoid to ensure efficient performance?

One common pitfall to avoid when implementing pagination in PHP is fetching and displaying all database results at once, which can lead to performance issues with large datasets. To ensure efficient performance, limit the number of results fetched from the database per page and utilize SQL LIMIT and OFFSET clauses to fetch only the necessary data for each page.

$page = isset($_GET['page']) ? $_GET['page'] : 1;
$results_per_page = 10;
$offset = ($page - 1) * $results_per_page;

$query = "SELECT * FROM table_name LIMIT $results_per_page OFFSET $offset";
// Execute the query and display the results