Add: ranking hour, day, month record php

This commit is contained in:
2018-05-18 09:52:58 +09:00
parent 8fe5c72987
commit 60bd151c92
18 changed files with 404 additions and 158 deletions
+1
View File
@@ -16,6 +16,7 @@
<!-- library source files -->
<script src="../../game/lib/number_util.js"></script>
<script src="../../game/lib/string_util.js"></script>
<script src="../../game/lib/history_record_manager.js"></script>
<script src="../../game/lib/ranking_record_manager.js"></script>
<script src="../../game/lib/db_connect_manager.js"></script>
+1
View File
@@ -16,6 +16,7 @@
<!-- library source files -->
<script src="../../game/lib/number_util.js"></script>
<script src="../../game/lib/string_util.js"></script>
<script src="../../game/lib/history_record_manager.js"></script>
<script src="../../game/lib/db_connect_manager.js"></script>
<script src="../../game/lib/input_type_text.js"></script>
+9 -9
View File
@@ -1,12 +1,12 @@
<?php
header('Content-Type: application/json');
include "./../send_error_code.php";
include "./../lib/send_error_code.php";
$user_id = $_POST["UserID"];
$app_name = $_POST["AppName"];
include "./../connect_db.php";
include "./../setup/connect_db.php";
// my ranking
@@ -25,15 +25,15 @@ $stmt->execute();
$stmt->bind_result($date, $score, $app_name);
$bestRecordArray = array();
$history_record_array = array();
while($stmt->fetch()) {
$best_record['Date'] = $date;
$best_record['HighScore'] = $score;
$best_record['AppName'] = $app_name;
array_push($bestRecordArray, $best_record);
array_push($return_array, $best_record);
$history_record['Date'] = $date;
$history_record['HighScore'] = $score;
$history_record['AppName'] = $app_name;
array_push($history_record_array, $history_record);
array_push($return_array, $history_record);
}
$return_array['history'] = $bestRecordArray;
$return_array['history'] = $history_record_array;
echo json_encode($return_array, JSON_UNESCAPED_UNICODE);
@@ -0,0 +1,49 @@
<?php
header('Content-Type: application/json');
include "./../lib/send_error_code.php";
$user_id = $_POST["UserID"];
$app_name = $_POST["AppName"];
include "./../setup/connect_db.php";
// ranking day
/*
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.Score) AS HighScore
FROM moty_record D, moty_user U
WHERE D.userID = U.userID AND DATE(D.DateTime) = DATE(NOW()) AND AppName = ?
GROUP BY D.userID
ORDER BY max(D.Score) DESC;
";
*/
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.Score) AS HighScore
FROM moty_record D, moty_user U
WHERE D.userID = U.userID AND DATE(D.DateTime) = DATE('2018-05-16') AND AppName = 'korean_word'
GROUP BY D.userID
ORDER BY max(D.Score) DESC;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $app_name);
$stmt->execute();
$stmt->bind_result($userID, $name, $high_score);
$score_record_array = array();
while($stmt->fetch()) {
$score_record['UserID'] = $userID;
$score_record['Name'] = $name;
$score_record['HighScore'] = $high_score;
array_push($score_record_array, $score_record);
}
$return_array['rankingDay'] = $score_record_array;
echo json_encode($return_array, JSON_UNESCAPED_UNICODE);
$db_conn->close();
?>
@@ -0,0 +1,49 @@
<?php
header('Content-Type: application/json');
include "./../lib/send_error_code.php";
$user_id = $_POST["UserID"];
$app_name = $_POST["AppName"];
include "./../setup/connect_db.php";
// ranking hour
/*
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.Score) AS HighScore
FROM moty_record D, moty_user U
WHERE D.userID = U.userID AND DATE(D.DateTime) = DATE(NOW()) AND HOUR(D.DateTime) = HOUR(NOW()) AND AppName = ?
GROUP BY D.userID
ORDER BY max(D.Score) DESC;
";
*/
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.Score) AS HighScore
FROM moty_record D, moty_user U
WHERE D.userID = U.userID AND DATE(D.DateTime) = DATE('2018-05-16') AND HOUR(D.DateTime) = HOUR('13:05:05') AND AppName = 'korean_word'
GROUP BY D.userID
ORDER BY max(D.Score) DESC;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $app_name);
$stmt->execute();
$stmt->bind_result($userID, $name, $high_score);
$score_record_array = array();
while($stmt->fetch()) {
$score_record['UserID'] = $userID;
$score_record['Name'] = $name;
$score_record['HighScore'] = $high_score;
array_push($score_record_array, $score_record);
}
$return_array['rankingHour'] = $score_record_array;
echo json_encode($return_array, JSON_UNESCAPED_UNICODE);
$db_conn->close();
?>
@@ -0,0 +1,40 @@
<?php
header('Content-Type: application/json');
include "./../lib/send_error_code.php";
$user_id = $_POST["UserID"];
$app_name = $_POST["AppName"];
include "./../setup/connect_db.php";
// ranking month
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.score) AS HighScore
FROM afterschool_record D, afterschool_user U
WHERE D.userID = U.userID AND MONTH(D.DateTime) = MONTH(NOW()) AND AppName = ?
GROUP BY D.userID
ORDER BY max(D.Record) DESC;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $app_name);
$stmt->execute();
$stmt->bind_result($userID, $name, $high_score);
$score_record_array = array();
while($stmt->fetch()) {
$score_record['UserID'] = $userID;
$score_record['Name'] = $name;
$score_record['HighScore'] = $high_score;
array_push($score_record_array, $score_record);
}
$return_array['rankingMonth'] = $score_record_array;
echo json_encode($return_array, JSON_UNESCAPED_UNICODE);
$db_conn->close();
?>
+88
View File
@@ -0,0 +1,88 @@
<?php
header('Content-Type: application/json');
include "./../lib/send_error_code.php";
$user_id = $_POST["UserID"];
$app_name = $_POST["AppName"];
include "./../setup/connect_db.php";
// ranking hour
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.score) AS HighScore
FROM afterschool_record D, afterschool_user U
WHERE D.userID = U.userID AND DATE(D.DateTime) = DATE(NOW()) AND HOUR(D.DateTime) = HOUR(NOW()) AND AppName = ?
GROUP BY D.userID
ORDER BY max(D.Record) DESC;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $app_name);
$stmt->execute();
$stmt->bind_result($userID, $name, $record);
$score_record_array = array();
while($stmt->fetch()) {
$score_record['UserID'] = $userID;
$score_record['Name'] = $name;
$score_record['HighScore'] = $record;
array_push($score_record_array, $score_record);
}
$return_array['rankingHour'] = $score_record_array;
// ranking day
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.record) AS HighScore
FROM afterschool_record D, afterschool_user U
WHERE D.userID = U.userID AND DATE(D.DateTime) = DATE(NOW()) AND AppName = ?
GROUP BY D.userID
ORDER BY max(D.Record) DESC;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $app_name);
$stmt->execute();
$stmt->bind_result($userID, $name, $record);
$score_record_array = array();
while($stmt->fetch()) {
$score_record['UserID'] = $userID;
$score_record['Name'] = $name;
$score_record['HighScore'] = $record;
array_push($score_record_array, $score_record);
}
$return_array['rankingDay'] = $score_record_array;
// ranking month
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.record) AS HighScore
FROM afterschool_record D, afterschool_user U
WHERE D.userID = U.userID AND MONTH(D.DateTime) = MONTH(NOW()) AND AppName = ?
GROUP BY D.userID
ORDER BY max(D.Record) DESC;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $app_name);
$stmt->execute();
$stmt->bind_result($userID, $name, $record);
$score_record_array = array();
while($stmt->fetch()) {
$score_record['UserID'] = $userID;
$score_record['Name'] = $name;
$score_record['HighScore'] = $record;
array_push($score_record_array, $score_record);
}
$return_array['rankingMonth'] = $score_record_array;
echo json_encode($return_array, JSON_UNESCAPED_UNICODE);
$db_conn->close();
?>
-118
View File
@@ -1,118 +0,0 @@
<?php
header('Content-Type: application/json');
include "send_error_code.php";
$user_id = $_POST["UserID"];
$language = $_POST["language"];
$stageNameDetail = $_POST["stageName"];
$stageName = $language."_".$stageNameDetail;
include "connect_db.php";
// my ranking
$query = "
SELECT DATE(RecordDateTime) AS Date, MAX(Record) AS BestRecord, StageName AS StageName
FROM afterschool_record D
WHERE UserID = ?
GROUP BY DATE(RecordDateTime)
ORDER BY RecordDateTime DESC;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $user_id);
$stmt->execute();
$stmt->bind_result($date, $record, $stage_name);
$bestRecordArray = array();
while($stmt->fetch()) {
$best_record['Date'] = $date;
$best_record['BestRecord'] = $record;
$best_record['StageName'] = $stage_name;
array_push($bestRecordArray, $best_record);
array_push($return_array, $best_record);
}
$return_array['myRanking'] = $bestRecordArray;
// ranking hour
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.record) AS BestRecord
FROM afterschool_record D, afterschool_user U
WHERE D.userID = U.userID AND DATE(D.RecordDateTime) = DATE(NOW()) AND HOUR(D.RecordDateTime) = HOUR(NOW()) AND StageName = ?
GROUP BY D.userID
ORDER BY max(D.Record) DESC;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $stageName);
$stmt->execute();
$stmt->bind_result($userID, $name, $record);
$bestRecordArray = array();
while($stmt->fetch()) {
$best_record['UserID'] = $userID;
$best_record['Name'] = $name;
$best_record['BestRecord'] = $record;
array_push($bestRecordArray, $best_record);
// array_push($return_array, $best_record);
}
$return_array['rankingHour'] = $bestRecordArray;
// ranking day
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.record) AS BestRecord
FROM afterschool_record D, afterschool_user U
WHERE D.userID = U.userID AND DATE(D.RecordDateTime) = DATE(NOW()) AND StageName = ?
GROUP BY D.userID
ORDER BY max(D.Record) DESC;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $stageName);
$stmt->execute();
$stmt->bind_result($userID, $name, $record);
$bestRecordArray = array();
while($stmt->fetch()) {
$best_record['UserID'] = $userID;
$best_record['Name'] = $name;
$best_record['BestRecord'] = $record;
array_push($bestRecordArray, $best_record);
// array_push($return_array, $best_record);
}
$return_array['rankingDay'] = $bestRecordArray;
// ranking month
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.record) AS BestRecord
FROM afterschool_record D, afterschool_user U
WHERE D.userID = U.userID AND MONTH(D.RecordDateTime) = MONTH(NOW()) AND StageName = ?
GROUP BY D.userID
ORDER BY max(D.Record) DESC;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $stageName);
$stmt->execute();
$stmt->bind_result($userID, $name, $record);
$bestRecordArray = array();
while($stmt->fetch()) {
$best_record['UserID'] = $userID;
$best_record['Name'] = $name;
$best_record['BestRecord'] = $record;
array_push($bestRecordArray, $best_record);
// array_push($return_array, $best_record);
}
$return_array['rankingMonth'] = $bestRecordArray;
echo json_encode($return_array, JSON_UNESCAPED_UNICODE);
$db_conn->close();
?>