What are the potential pitfalls of using the LIMIT clause in a MySQL query for pagination in PHP?

Using the LIMIT clause for pagination in MySQL can lead to performance issues when dealing with large datasets, as the database has to process the entire result set before applying the limit. To solve this, you can use the OFFSET clause along with LIMIT to fetch only a subset of the data at a time, improving efficiency.

$page = $_GET['page']; // Current page number
$limit = 10; // Number of results per page
$offset = ($page - 1) * $limit; // Calculate the offset

$query = "SELECT * FROM table_name LIMIT $limit OFFSET $offset";
$result = mysqli_query($connection, $query);

// Fetch and display results