Are there any potential pitfalls or performance issues to consider when implementing pagination in PHP using MySQL queries?

One potential performance issue to consider when implementing pagination in PHP using MySQL queries is the use of OFFSET in the query. When using OFFSET, MySQL has to scan through all the records before skipping to the desired offset, which can be slow for large datasets. To improve performance, you can use the LIMIT clause with a higher OFFSET value as the page number increases.

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

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

// Fetch and display the results