The issue is that when the user clicks on the pagination links, the loadData function is called with the new page number, but it doesn't pass the selected ID to the API call. To fix this, you need to modify the loadData function to include the selected ID in the API call.
Here's an updated version of the loadData function:
function loadData(page) {
var url = window.location.href.split('?')[0] + '?page=' + page;
var selectedID = getSelectedID();
if (selectedID) {
url += '&ID=' + selectedID;
}
window.location.href = url;
}
function getSelectedID() {
var urlParams = new URLSearchParams(window.location.search);
return urlParams.get('ID');
}
This function first gets the current URL and appends the page parameter with the new page number. Then it checks if there's a selected ID and appends it to the URL if it exists. Finally, it sets the window.location.href to the new URL, which will trigger a page reload with the new parameters.
You also need to modify the PHP code to include the selected ID in the API call. Here's the updated code:
if(isset($_GET['ID'])) {
$selectedID = $_GET['ID'];
} else {
foreach($hunts as $bonushunt) {
$selectedID = $bonushunt->id;
}
}
$response = file_get_contents('https://bht.bet/api/dzWJjyef5PIbA1nMjQPW2KTTy1gfqUiw/hunts/'.$selectedID, false, $context);
This code first checks if there's a selected ID in the URL and uses it if it exists. Otherwise, it loops through the $hunts array and uses the first ID as the default. Then it includes the selected ID in the API call using string concatenation.
With these changes, the selected ID should be preserved when the user clicks on the pagination links.