How can the LIMIT clause in MySQL queries impact the pagination functionality in PHP scripts?

When using the LIMIT clause in MySQL queries for pagination in PHP scripts, it can impact the functionality by not returning the correct results for each page. To solve this issue, you need to adjust the query to calculate the offset dynamically based on the current page and the number of results per page.

<?php
// Define pagination variables
$results_per_page = 10;
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$offset = ($page - 1) * $results_per_page;

// Query with dynamic LIMIT and OFFSET
$query = "SELECT * FROM table_name LIMIT $offset, $results_per_page";

// Execute query and fetch results
// Display results on the page
?>