-
Notifications
You must be signed in to change notification settings - Fork 21
/
get_uncompleted_characters.php
49 lines (42 loc) · 1.32 KB
/
get_uncompleted_characters.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
40
41
42
43
44
45
46
47
48
49
<?php
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
header("Content-Type: text/plain; charset=UTF-8");
require_once("../../lib/CONSTANTS.inc");
require_once("../../lib/db.inc");
$connection = getConnection();
$x = $_GET["x"];
$list = array();
try {
$query =
"SELECT id,title,author,y FROM characters WHERE x IS NULL AND active = 1";
$resultset = mysql_query($query, $connection) or
throwException(mysql_error());
$ids = "";
while ($row = mysql_fetch_array($resultset)) {
$character = array();
$id = intval($row["id"]);
$character["id"] = $id;
$character["title"] = $row["title"];
$character["author"] = $row["author"];
$character["y"] = intval($row["y"]);
$character["x"] = $x;
array_push($list, $character);
if (strlen($ids) != 0) {
$ids .= ",";
}
$ids .= $id;
}
mysql_free_result($resultset);
// Update
if (strlen($ids) != 0) {
$query4update = "UPDATE characters set x=$x WHERE id IN ($ids)";
mysql_query($query4update, $connection) or throwException(mysql_error());
}
} catch (Exception $e) {
$list["error"] = $e->getMessage();
}
mysql_close($connection);
echo json_encode($list);
?>