diff --git a/api/domains.php b/api/domains.php index 1b47ee7..559ea59 100644 --- a/api/domains.php +++ b/api/domains.php @@ -28,7 +28,12 @@ if(!isset($input->csrfToken) || $input->csrfToken !== $_SESSION['csrfToken']) { } if(isset($input->action) && $input->action == "getDomains") { - + // Check if the requested page is a number + if(!(is_int($input->page) && $input->page > 0)) { + echo "Requested page must be a positive number!"; + exit(); + } + // Here we get the number of matching records $sql = " SELECT COUNT(*) AS anzahl @@ -75,7 +80,7 @@ if(isset($input->action) && $input->action == "getDomains") { // Initialize the return value $retval = Array(); - $retval['pages']['current'] = 4000; + $retval['pages']['current'] = $input->page; $retval['pages']['total'] = ceil($obj->anzahl / $config['domain_rows']); @@ -113,10 +118,15 @@ if(isset($input->action) && $input->action == "getDomains") { } /* - * Now the number of entries gets limited to the domainRows config value + * Now the number of entries gets limited to the domainRows config value. + * SQL LIMIT is used for that: + * LIMIT lower, upper + * Note that LIMIT 0,4 returns the first five rows! */ - $sql .= " LIMIT " . $config['domain_rows']; - + $lower_limit = ($config['domain_rows'] * ($input->page - 1)); + + $sql .= " LIMIT " . $lower_limit . ", " . $config['domain_rows']; + $stmt = $db->prepare($sql); if(isset($input->name)) { diff --git a/js/domains.js b/js/domains.js index 8d6534a..6a464fc 100644 --- a/js/domains.js +++ b/js/domains.js @@ -20,7 +20,8 @@ var sort = { } $(document).ready(function() { - requestData(); + // When the site is loaded, always show the first page + requestData(1); $('#table-domains>thead>tr>td span').click(function() { var field = $(this).siblings('strong').text().toLowerCase(); @@ -53,7 +54,7 @@ $(document).ready(function() { }); }); -function requestData() { +function requestData(page) { var restrictions = { csrfToken: $('#csrfToken').text(), }; @@ -71,6 +72,7 @@ function requestData() { } restrictions.action = "getDomains"; + restrictions.page = page; $.post( "api/domains.php", @@ -189,5 +191,5 @@ function deleteDomainWithId(id, callback) { } function paginationClicked() { - alert($(this).data("page")); + requestData($(this).data("page")); } \ No newline at end of file