-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapSelectData.php
39 lines (35 loc) · 1.12 KB
/
mapSelectData.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
require("config.php");
if(empty($_SESSION['user']))
{
header("Location: index.php");
die("Redirecting to index.php");
}
$totalMaps = $db->query('SELECT COUNT(id) from maps')->fetchColumn();
$ipp = 6; //items per page
$totalPages = ceil($totalMaps/$ipp);
if($_POST['param']=="init"){
$stmt = $db->prepare('SELECT * FROM maps LIMIT 0, :ipp');
$stmt->bindValue(':ipp', (int)trim($ipp), PDO::PARAM_INT);
$stmt->execute();
foreach ($stmt as $row) {
$data['id'][] = $row['id'];
$data['name'][] = $row['name'];
$data['mapProperties'][] = $row['mapProperties'];
}
$data['totalPages'] = $totalPages;
echo JSON_encode($data);
}
if($_POST['param']=="page"){
$stmt = $db->prepare('SELECT * FROM maps LIMIT :start, :end');
$stmt->bindValue(':start', (int)trim(($_POST['page']-1)*$ipp), PDO::PARAM_INT);
$stmt->bindValue(':end', (int)trim(($_POST['page']-1)*$ipp+$ipp), PDO::PARAM_INT);
$stmt->execute();
foreach ($stmt as $row) {
$data['id'][] = $row['id'];
$data['name'][] = $row['name'];
$data['mapProperties'][] = $row['mapProperties'];
}
echo JSON_encode($data);
}
?>