Pagination on API and not UI (v2024)

I am trying to fix pagnation from API and not the UI.

This is my code :

$app->get('/renterproperties/{state}', function ($request, $response, $args) {
    $state = AdjustSql($args['state']);

    $lastId = (int) ($request->getQueryParams()['last_id'] ?? 0);

    $sql = "
        SELECT *
        FROM properties
        WHERE state_id = '$state'
          AND id > $lastId
        ORDER BY id
        LIMIT 10
    ";

    return $response->withJson(ExecuteRows($sql));
});

My problem now is $lastId = (int) ($request->getQueryParams()['last_id'] ?? 0); how to get the last ID . My code is in Api_Action. phpmaker 2024

My bad last_id will come from URL. Thanks

Since you write your own API (not the built-in REST API which is stateless), you may use session variable to save the last ID. If it is from URL, your code should work.