Fix: revised php code to maestro search

This commit is contained in:
2018-07-12 10:55:44 +09:00
parent 7aa212ee47
commit f23665a5f0
12 changed files with 339 additions and 227 deletions
+14 -14
View File
@@ -1,25 +1,27 @@
<?php
header('Content-Type: application/json');
header("Content-Type: application/json");
include "./../lib/send_reply_json.php";
include "./../setup/connect_db.php";
$maestroID = $_POST["maestro_id"];
$playerName = $_POST["player_name"];
$enterCode = $_POST["enter_code"];
/*
if(!is_numeric($enterCode)) {
send_error_code('생년월일이 숫자가 아닙니다. : '.$enterCode);
send_error_code("생년월일이 숫자가 아닙니다. : ".$enterCode);
exit;
} else if(strlen($enterCode) != 6) {
send_error_code('6자리 숫자값을 정확히 입력하세요 : YYMMDD (예 : 120131) : '.$enterCode);
send_error_code("6자리 숫자값을 정확히 입력하세요 : YYMMDD (예 : 120131) : ".$enterCode);
exit;
}
*/
include "./../setup/connect_db.php";
$result = hasPlayerName($maestroID, $playerName, $enterCode);
if($result !== null) {
send_error_message($replyJSON, "이미 등록된 학생과 입장 코드 정보입니다.");
// $db_conn->close();
set_error_message("이미 등록된 학생과 입장 코드 정보입니다.");
send_result_fail();
exit;
}
@@ -27,15 +29,13 @@ addPlayer($maestroID, $playerName, $enterCode);
$result = hasPlayerName($maestroID, $playerName, $enterCode);
if($result === null) {
send_result_message($replyJSON, "fail");
exit;
} else {
send_result_message($replyJSON, "success");
set_error_message("학생 등록에 실패했습니다.");
send_result_fail();
exit;
}
// echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
// $db_conn->close();
send_result_success();
exit;
function hasPlayerName($maestroID, $playerName, $enterCode) {
@@ -43,7 +43,7 @@ function hasPlayerName($maestroID, $playerName, $enterCode) {
$query = "SELECT PlayerID FROM moty_player WHERE MaestroID=? AND Name=? AND EnterCode=?";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('iss', $maestroID, $playerName, $enterCode);
$stmt->bind_param("iss", $maestroID, $playerName, $enterCode);
$stmt->execute();
$stmt->bind_result($playerID);
// while($stmt->fetch())
@@ -58,7 +58,7 @@ function addPlayer($maestroID, $playerName, $enterCode) {
$query = "INSERT INTO moty_player (MaestroID, Name, EnterCode) VALUES (?, ?, ?)";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('iss', $maestroID, $playerName, $enterCode);
$stmt->bind_param("iss", $maestroID, $playerName, $enterCode);
$stmt->execute();
}
+14 -20
View File
@@ -1,37 +1,31 @@
<?php
header('Content-Type: application/json');
header("Content-Type: application/json");
include "./../lib/send_reply_json.php";
include "./../setup/connect_db.php";
$maestroID = $_POST["maestro_id"];
$playerID = $_POST["player_id"];
/*
if(!is_numeric($enterCode)) {
send_error_code('생년월일이 숫자가 아닙니다. : '.$enterCode);
exit;
} else if(strlen($enterCode) != 6) {
send_error_code('6자리 숫자값을 정확히 입력하세요 : YYMMDD (예 : 120131) : '.$enterCode);
exit;
}
*/
include "./../setup/connect_db.php";
deletePlayer($maestroID, $playerID);
$result = hasPlayerID($maestroID, $playerID);
if($result === true) {
send_result_message($replyJSON, "학생 계정 삭제 실패");
set_error_message("학생 계정 삭제 실패");
send_result_fail();
exit;
}
$result = hasPlayerRecord($maestroID, $playerID);
if($result === true) {
send_result_message($replyJSON, "학생 플레이 기록 삭제 실패");
set_error_message("학생 플레이 기록 삭제 실패");
send_result_fail();
exit;
}
$replyJSON["RESULT"] = "success";
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
$db_conn->close();
send_result_success();
exit;
function deletePlayer($maestroID, $playerID) {
@@ -39,7 +33,7 @@ function deletePlayer($maestroID, $playerID) {
$query = "DELETE FROM moty_best_record WHERE MaestroID = ? AND PlayerID = ?";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('ii', $maestroID, $playerID);
$stmt->bind_param("ii", $maestroID, $playerID);
$result = $stmt->execute();
$stmt->close();
@@ -49,7 +43,7 @@ function deletePlayer($maestroID, $playerID) {
$query = "DELETE FROM moty_player WHERE MaestroID = ? AND PlayerID = ?";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('ii', $maestroID, $playerID);
$stmt->bind_param("ii", $maestroID, $playerID);
$result = $stmt->execute();
$stmt->close();
@@ -63,7 +57,7 @@ function hasPlayerID($maestroID, $playerID) {
$query = "SELECT PlayerID FROM moty_player WHERE MaestroID=? AND PlayerID=?";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('ii', $maestroID, $playerID);
$stmt->bind_param("ii", $maestroID, $playerID);
$stmt->execute();
$stmt->bind_result($playerID);
// while($stmt->fetch())
@@ -81,7 +75,7 @@ function hasPlayerRecord($maestroID, $playerID) {
$query = "SELECT PlayerID FROM moty_best_record WHERE MaestroID=? AND PlayerID=?";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('ii', $maestroID, $playerID);
$stmt->bind_param("ii", $maestroID, $playerID);
$stmt->execute();
$stmt->bind_result($playerID);
// while($stmt->fetch())
+16 -13
View File
@@ -1,5 +1,8 @@
<?php
header('Content-Type: application/json');
header("Content-Type: application/json");
include "./../lib/send_reply_json.php";
include "./../setup/connect_db.php";
$maestroID = $_POST["maestro_id"];
$playerID = $_POST["player_id"];
@@ -7,20 +10,19 @@ $playerName = $_POST["player_name"];
$enterCode = $_POST["enter_code"];
/*
if(!is_numeric($enterCode)) {
send_error_code('생년월일이 숫자가 아닙니다. : '.$enterCode);
send_error_code("생년월일이 숫자가 아닙니다. : ".$enterCode);
exit;
} else if(strlen($enterCode) != 6) {
send_error_code('6자리 숫자값을 정확히 입력하세요 : YYMMDD (예 : 120131) : '.$enterCode);
send_error_code("6자리 숫자값을 정확히 입력하세요 : YYMMDD (예 : 120131) : ".$enterCode);
exit;
}
*/
include "./../setup/connect_db.php";
$result = hasSamePlayerData($maestroID, $playerID, $playerName, $enterCode);
if($result > 0) {
send_error_message($replyJSON, "이미 등록된 학생과 입장 코드 정보입니다.");
// $db_conn->close();
set_error_message("이미 등록된 학생과 입장 코드 정보입니다.");
send_result_fail();
exit;
}
@@ -28,20 +30,21 @@ editPlayer($maestroID, $playerID, $playerName, $enterCode);
$result = hasPlayerName($maestroID, $playerName, $enterCode);
if($result === null) {
send_result_message($replyJSON, "fail");
set_error_message("학생 등록에 실패했습니다.");
send_result_fail();
exit;
}
$replyJSON["RESULT"] = "success";
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
$db_conn->close();
send_result_success();
exit;
function hasSamePlayerData($maestroID, $playerID, $playerName, $enterCode) {
global $db_conn;
$query = "SELECT COUNT(PlayerID) FROM moty_player WHERE MaestroID=? AND PlayerID<>? AND Name=? AND EnterCode=?";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('iiss', $maestroID, $playerID, $playerName, $enterCode);
$stmt->bind_param("iiss", $maestroID, $playerID, $playerName, $enterCode);
$stmt->execute();
$stmt->bind_result($playerCount);
// while($stmt->fetch())
@@ -56,7 +59,7 @@ function editPlayer($maestroID, $playerID, $playerName, $enterCode) {
$query = "UPDATE moty_player SET Name=?, EnterCode=? WHERE MaestroID=? AND PlayerID=?";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('ssii', $playerName, $enterCode, $maestroID, $playerID);
$stmt->bind_param("ssii", $playerName, $enterCode, $maestroID, $playerID);
$stmt->execute();
}
@@ -65,7 +68,7 @@ function hasPlayerName($maestroID, $playerName, $enterCode) {
$query = "SELECT PlayerID FROM moty_player WHERE MaestroID=? AND Name=? AND EnterCode=?";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('iss', $maestroID, $playerName, $enterCode);
$stmt->bind_param("iss", $maestroID, $playerName, $enterCode);
$stmt->execute();
$stmt->bind_result($playerID);
// while($stmt->fetch())
@@ -1,30 +1,22 @@
<?php
header('Content-Type: application/json');
$maestroID = $_POST["maestro_id"];
/*
if(!is_numeric($enterCode)) {
send_error_code('생년월일이 숫자가 아닙니다. : '.$enterCode);
exit;
} else if(strlen($enterCode) != 6) {
send_error_code('6자리 숫자값을 정확히 입력하세요 : YYMMDD (예 : 120131) : '.$enterCode);
exit;
}
*/
header("Content-Type: application/json");
include "./../lib/send_reply_json.php";
include "./../setup/connect_db.php";
$result = getPlayerCount($maestroID);
$maestroID = $_POST["maestro_id"];
$playerCount = getPlayerCount($maestroID);
if($result === null) {
send_error_message($replyJSON, "등록된 학생이 없습니다.");
// $db_conn->close();
set_error_message("등록된 학생이 없습니다.");
send_result_fail();
exit;
}
$replyJSON["Count"] = $result;
$replyJSON["RESULT"] = "ok";
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
$db_conn->close();
set_data("playerCount", $playerCount);
send_result_success();
exit;
function getPlayerCount($maestroID) {
@@ -32,7 +24,7 @@ function getPlayerCount($maestroID) {
$query = "SELECT COUNT(PlayerID) FROM moty_player WHERE MaestroID=?";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('i', $maestroID);
$stmt->bind_param("i", $maestroID);
$stmt->execute();
$stmt->bind_result($playerCount);
$stmt->fetch();
@@ -1,23 +1,24 @@
<?php
header('Content-Type: application/json');
header("Content-Type: application/json");
include "./../lib/send_reply_json.php";
include "./../setup/connect_db.php";
$maestroID = $_POST["maestro_id"];
$startNo = $_POST["start_no"];
$endNo = $_POST["end_no"];
include "./../setup/connect_db.php";
$replyJSON = get_player_list_page($maestroID, $startNo, $endNo);
if($replyJSON.length === 0) {
send_error_message($replyJSON, "오늘의 랭킹 기록 없음");
$db_conn->close();
$playerList = get_player_list_page($maestroID, $startNo, $endNo);
if(strlen($playerList) === 0) {
set_error_message("오늘의 랭킹 기록 없음");
send_result_fail();
exit;
}
$replyJSON["RESULT"] = "ok";
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
$db_conn->close();
set_data("playerList", $playerList);
send_result_success();
exit;
function get_player_list_page($maestroID, $startNo, $endNo) {
@@ -30,21 +31,20 @@ function get_player_list_page($maestroID, $startNo, $endNo) {
LIMIT ?, 10;
";
$stmt = $db_conn->prepare($query);
// $stmt->bind_param('iii', $maestroID, $startNo, $endNo);
$stmt->bind_param('ii', $maestroID, $startNo);
// $stmt->bind_param("iii", $maestroID, $startNo, $endNo);
$stmt->bind_param("ii", $maestroID, $startNo);
$stmt->execute();
$stmt->bind_result($playerID, $name, $enterCode);
$playerList = array();
while($stmt->fetch()) {
$player['PlayerID'] = $playerID;
$player['Name'] = $name;
$player['EnterCode'] = $enterCode;
$player["playerID"] = $playerID;
$player["playerName"] = $name;
$player["enterCode"] = $enterCode;
array_push($playerList, $player);
}
$return_array['PlayerList'] = $playerList;
return $return_array;
return $playerList;
}
?>
+12 -21
View File
@@ -1,39 +1,30 @@
<?php
header('Content-Type: application/json');
header("Content-Type: application/json");
include "./../lib/send_reply_json.php";
include "./../setup/connect_db.php";
$maestroID = $_POST["maestro_id"];
$playerName = $_POST["player_name"];
/*
if(!is_numeric($enterCode)) {
send_error_code('생년월일이 숫자가 아닙니다. : '.$enterCode);
exit;
} else if(strlen($enterCode) != 6) {
send_error_code('6자리 숫자값을 정확히 입력하세요 : YYMMDD (예 : 120131) : '.$enterCode);
exit;
}
*/
include "./../setup/connect_db.php";
$result = getPlayerCount($maestroID, $playerName);
if($result === null) {
send_error_message($replyJSON, "등록된 학생이 없습니다.");
// $db_conn->close();
$playerCount = getPlayerCount($maestroID, $playerName);
if($playerCount === null) {
set_error_message("등록된 학생이 없습니다.");
send_result_fail();
exit;
}
$replyJSON["Count"] = $result;
$replyJSON["RESULT"] = "ok";
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
$db_conn->close();
set_data("playerCount", $playerCount);
send_result_success();
exit;
function getPlayerCount($maestroID, $playerName) {
global $db_conn;
$query = "SELECT COUNT(PlayerID) FROM moty_player WHERE MaestroID = ? AND Name = ?";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('is', $maestroID, $playerName);
$stmt->bind_param("is", $maestroID, $playerName);
$stmt->execute();
$stmt->bind_result($playerCount);
$stmt->fetch();
+17 -17
View File
@@ -1,24 +1,25 @@
<?php
header('Content-Type: application/json');
header("Content-Type: application/json");
include "./../lib/send_reply_json.php";
include "./../setup/connect_db.php";
$maestroID = $_POST["maestro_id"];
$playerName = $_POST["player_name"];
$startNo = $_POST["start_no"];
$endNo = $_POST["end_no"];
include "./../setup/connect_db.php";
$replyJSON = get_player_list_page($maestroID, $playerName, $startNo, $endNo);
if($replyJSON.length === 0) {
send_error_message($replyJSON, "해당 이름으로 등록된 학생 없음");
$db_conn->close();
$playerList = get_player_list_page($maestroID, $playerName, $startNo, $endNo);
if($playerList.length === 0) {
set_error_message("해당 이름으로 등록된 학생 없음");
send_result_fail();
exit;
}
$replyJSON["RESULT"] = "ok";
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
$db_conn->close();
set_data("playerList", $playerList);
send_result_success();
exit;
function get_player_list_page($maestroID, $playerName, $startNo, $endNo) {
@@ -31,21 +32,20 @@ function get_player_list_page($maestroID, $playerName, $startNo, $endNo) {
LIMIT ?, 10;
";
$stmt = $db_conn->prepare($query);
// $stmt->bind_param('iii', $maestroID, $startNo, $endNo);
$stmt->bind_param('isi', $maestroID, $playerName, $startNo);
// $stmt->bind_param("iii", $maestroID, $startNo, $endNo);
$stmt->bind_param("isi", $maestroID, $playerName, $startNo);
$stmt->execute();
$stmt->bind_result($playerID, $name, $enterCode);
$playerList = array();
while($stmt->fetch()) {
$player['PlayerID'] = $playerID;
$player['Name'] = $name;
$player['EnterCode'] = $enterCode;
$player["playerID"] = $playerID;
$player["playerName"] = $name;
$player["enterCode"] = $enterCode;
array_push($playerList, $player);
}
$return_array['PlayerList'] = $playerList;
return $return_array;
return $playerList;
}
?>