What are some common pitfalls to avoid when trying to implement a pagination feature in PHP for displaying database entries?

One common pitfall to avoid when implementing pagination in PHP is not properly sanitizing user input, which can lead to SQL injection attacks. To prevent this, always use prepared statements or parameterized queries when interacting with the database.

// Example of using prepared statements to prevent SQL injection

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

$stmt = $pdo->prepare("SELECT * FROM table_name LIMIT :limit OFFSET :offset");
$stmt->bindParam(':limit', $limit, PDO::PARAM_INT);
$stmt->bindParam(':offset', $offset, PDO::PARAM_INT);
$stmt->execute();

// Fetch and display results