What potential pitfalls should be considered when limiting the number of entries displayed per page in PHP?

When limiting the number of entries displayed per page in PHP, it is important to consider potential pitfalls such as pagination issues if the total number of entries is not accurately calculated, and performance concerns if a large number of entries are being queried and processed. To address these issues, make sure to accurately calculate the total number of entries, implement pagination logic to display the correct subset of entries per page, and consider optimizing queries for better performance.

// Calculate total number of entries
$total_entries = // query to get total number of entries

// Set limit of entries per page
$limit = 10;

// Get current page number
$page = isset($_GET['page']) ? $_GET['page'] : 1;

// Calculate offset for query
$offset = ($page - 1) * $limit;

// Query to get entries for current page
$query = "SELECT * FROM entries LIMIT $offset, $limit";
$result = // execute query

// Display entries
foreach($result as $entry){
    // display entry content
}