#pragma strict
import MySql.Data;
var connectionString = "Server=localhost;Database=gameproject;UserID=root;Password=;Pooling=true;";
var command:MySql.Data.MySqlClient.MySqlCommand;
var namesList= new Array();
var count:int;
var db : dbAccess;
var name;
var mySkin: GUISkin;
var cController: CrosshairController;
var highScore: int;
var startTime: float;
var firstName: String;


function Start () {
	cController = GameObject.FindGameObjectWithTag("Crosshair").GetComponent(CrosshairController);
	firstName = cController.GetSavedFirstName();
}

function Update () {
	DisplayPlayerHighScore();
}

function DisplayPlayerHighScore(){
	try
	{
		namesList = new Array();
		var connection = MySql.Data.MySqlClient.MySqlConnection(connectionString);
		connection.Open();
		command = MySql.Data.MySqlClient.MySqlCommand("SELECT player.Name, score.score FROM player INNER JOIN score ON player.ID= score.PlayerId WHERE player.Name = '" + firstName + "' ORDER BY Score DESC Limit 5",connection);
		var dataReader = command.ExecuteReader();	
		
		
		while(dataReader.Read())
		{
			namesList.Add(dataReader["Name"].ToString() + "  Score:   " + dataReader["Score"].ToString());
		}
		
		connection.Close();
		connection.Dispose();
		
	}catch(e){
		Debug.Log(e.ToString());
	}	
}

function OnGUI(){
	GUI.skin = mySkin;
	var textStyle = new GUIStyle(GUI.skin.label);
	
	count = 300;
	for(name in namesList){
		GUI.Label(Rect(650,count, 300, 50),"Name:  " + name,textStyle);
		count +=50;
	}

}

