Fix: add/delete player count bug
This commit is contained in:
@@ -43,8 +43,11 @@ if($result === null) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
increase_player_count($maestroID, 1);
|
// increase_player_count($maestroID, 1);
|
||||||
|
$count = count_registered_player($maestroID);
|
||||||
|
update_count_registered_player($maestroID, $count);
|
||||||
|
|
||||||
|
set_data("count", $count);
|
||||||
send_result_success();
|
send_result_success();
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
@@ -131,4 +134,36 @@ function increase_player_count($maestroID, $count) {
|
|||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function count_registered_player($maestroID) {
|
||||||
|
global $db_conn;
|
||||||
|
|
||||||
|
$query = "
|
||||||
|
SELECT COUNT(PlayerID)
|
||||||
|
FROM moty_player
|
||||||
|
WHERE MaestroID = ? AND AccountType = 0
|
||||||
|
";
|
||||||
|
$stmt = $db_conn->prepare($query);
|
||||||
|
$stmt->bind_param("i", $maestroID);
|
||||||
|
$stmt->execute();
|
||||||
|
$stmt->bind_result($countPlayer);
|
||||||
|
// while($stmt->fetch())
|
||||||
|
$stmt->fetch();
|
||||||
|
$stmt->close();
|
||||||
|
|
||||||
|
return $countPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
function update_count_registered_player($maestroID, $countPlayer) {
|
||||||
|
global $db_conn;
|
||||||
|
|
||||||
|
$query = "
|
||||||
|
UPDATE moty_maestro
|
||||||
|
SET PlayerCount = ?
|
||||||
|
WHERE MaestroID = ?
|
||||||
|
";
|
||||||
|
$stmt = $db_conn->prepare($query);
|
||||||
|
$stmt->bind_param("ii", $countPlayer, $maestroID);
|
||||||
|
$stmt->execute();
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -10,22 +10,25 @@ $playerID = $_POST["player_id"];
|
|||||||
|
|
||||||
deletePlayer($maestroID, $playerID);
|
deletePlayer($maestroID, $playerID);
|
||||||
|
|
||||||
$result = hasPlayerID($maestroID, $playerID);
|
$countPlayer = countPlayerID($maestroID, $playerID);
|
||||||
if($result === true) {
|
if($countPlayer > 0) {
|
||||||
set_error_message("학생 계정 삭제 실패");
|
set_error_message("학생 계정 삭제 실패");
|
||||||
send_result_fail();
|
send_result_fail();
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = hasPlayerRecord($maestroID, $playerID);
|
$countPlayer = countPlayerRecord($maestroID, $playerID);
|
||||||
if($result === true) {
|
if($countPlayer > 0) {
|
||||||
set_error_message("학생 플레이 기록 삭제 실패");
|
set_error_message("학생 플레이 기록 삭제 실패");
|
||||||
send_result_fail();
|
send_result_fail();
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
decrease_player_count($maestroID, 1);
|
// decrease_player_count($maestroID, 1);
|
||||||
|
$count = count_registered_player($maestroID);
|
||||||
|
update_count_registered_player($maestroID, $count);
|
||||||
|
|
||||||
|
set_data("count", $count);
|
||||||
send_result_success();
|
send_result_success();
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
@@ -60,48 +63,42 @@ function deletePlayer($maestroID, $playerID) {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasPlayerID($maestroID, $playerID) {
|
function countPlayerID($maestroID, $playerID) {
|
||||||
global $db_conn;
|
global $db_conn;
|
||||||
|
|
||||||
$query = "
|
$query = "
|
||||||
SELECT PlayerID
|
SELECT COUNT(PlayerID)
|
||||||
FROM moty_player
|
FROM moty_player
|
||||||
WHERE MaestroID=? AND PlayerID=?
|
WHERE MaestroID = ? AND PlayerID = ?
|
||||||
";
|
";
|
||||||
$stmt = $db_conn->prepare($query);
|
$stmt = $db_conn->prepare($query);
|
||||||
$stmt->bind_param("ii", $maestroID, $playerID);
|
$stmt->bind_param("ii", $maestroID, $playerID);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$stmt->bind_result($playerID);
|
$stmt->bind_result($countPlayer);
|
||||||
// while($stmt->fetch())
|
// while($stmt->fetch())
|
||||||
$stmt->fetch();
|
$stmt->fetch();
|
||||||
$stmt->close();
|
$stmt->close();
|
||||||
|
|
||||||
if($playerID !== null)
|
return $countPlayer;
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasPlayerRecord($maestroID, $playerID) {
|
function countPlayerRecord($maestroID, $playerID) {
|
||||||
global $db_conn;
|
global $db_conn;
|
||||||
|
|
||||||
$query = "
|
$query = "
|
||||||
SELECT PlayerID
|
SELECT COUNT(PlayerID)
|
||||||
FROM moty_best_record
|
FROM moty_best_record
|
||||||
WHERE MaestroID=? AND PlayerID=?
|
WHERE MaestroID = ? AND PlayerID = ?
|
||||||
";
|
";
|
||||||
$stmt = $db_conn->prepare($query);
|
$stmt = $db_conn->prepare($query);
|
||||||
$stmt->bind_param("ii", $maestroID, $playerID);
|
$stmt->bind_param("ii", $maestroID, $playerID);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$stmt->bind_result($playerID);
|
$stmt->bind_result($countPlayer);
|
||||||
// while($stmt->fetch())
|
// while($stmt->fetch())
|
||||||
$stmt->fetch();
|
$stmt->fetch();
|
||||||
$stmt->close();
|
$stmt->close();
|
||||||
|
|
||||||
if($playerID !== null)
|
return $countPlayer;
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function decrease_player_count($maestroID, $count) {
|
function decrease_player_count($maestroID, $count) {
|
||||||
@@ -117,4 +114,36 @@ function decrease_player_count($maestroID, $count) {
|
|||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function count_registered_player($maestroID) {
|
||||||
|
global $db_conn;
|
||||||
|
|
||||||
|
$query = "
|
||||||
|
SELECT COUNT(PlayerID)
|
||||||
|
FROM moty_player
|
||||||
|
WHERE MaestroID = ? AND AccountType = 0
|
||||||
|
";
|
||||||
|
$stmt = $db_conn->prepare($query);
|
||||||
|
$stmt->bind_param("i", $maestroID);
|
||||||
|
$stmt->execute();
|
||||||
|
$stmt->bind_result($countPlayer);
|
||||||
|
// while($stmt->fetch())
|
||||||
|
$stmt->fetch();
|
||||||
|
$stmt->close();
|
||||||
|
|
||||||
|
return $countPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
function update_count_registered_player($maestroID, $countPlayer) {
|
||||||
|
global $db_conn;
|
||||||
|
|
||||||
|
$query = "
|
||||||
|
UPDATE moty_maestro
|
||||||
|
SET PlayerCount = ?
|
||||||
|
WHERE MaestroID = ?
|
||||||
|
";
|
||||||
|
$stmt = $db_conn->prepare($query);
|
||||||
|
$stmt->bind_param("ii", $countPlayer, $maestroID);
|
||||||
|
$stmt->execute();
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -24,6 +24,7 @@ if($playerID === null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
set_data("MaestroID", $maestroID);
|
||||||
set_data("PlayerID", $playerID);
|
set_data("PlayerID", $playerID);
|
||||||
send_result_success();
|
send_result_success();
|
||||||
exit;
|
exit;
|
||||||
|
|||||||
Reference in New Issue
Block a user