<?php
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"];


$playerList = get_player_list_page($maestroID, $startNo, $endNo);
if(strlen($playerList) === 0) {
	set_error_message("오늘의 랭킹 기록 없음");
	send_result_fail();
	exit;
}

set_data("playerList", $playerList);
send_result_success();
exit;


function get_player_list_page($maestroID, $startNo, $endNo) {
	global $db_conn;

	$query = "
		SELECT PlayerID, Name, EnterCode FROM player
		WHERE MaestroID = ? AND AccountType <> 1
		ORDER BY PlayerID DESC
		LIMIT ?, 10;
	";
	$stmt = $db_conn->prepare($query);
	// $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["playerName"] = $name;
	    $player["enterCode"] = $enterCode;
	    array_push($playerList, $player);
	}

	return $playerList;
}

?>