How can pagination be implemented using Limit and Offset in PHP?

When implementing pagination in PHP using Limit and Offset, you can use these two parameters in your SQL query to limit the number of results fetched from the database and specify the starting point for fetching the results. By adjusting the Limit and Offset values based on the current page number and the number of results per page, you can display paginated data to the user.

// Set the current page number and number of results per page
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$results_per_page = 10;

// Calculate the Offset value based on the current page number
$offset = ($page - 1) * $results_per_page;

// Query to fetch paginated data using Limit and Offset
$sql = "SELECT * FROM your_table LIMIT $results_per_page OFFSET $offset";
$result = $conn->query($sql);

// Display the paginated data to the user
while($row = $result->fetch_assoc()) {
    // Display data here
}

// Pagination links
// You can generate pagination links based on the total number of results and the results per page