Question : How do I add a lap time to a Mysql database in a flash game using PHP

I am developing a flash racing game and wish to add fasted time to a highest score board however i am having difficulty in adding the time in sec, min, millsecs to a database.

The game is developed using AS2 and the script sending the time to the database is below.  The script at this stage does send rounded numbers but not time.

Hope sombody can help.

Thanks
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
//GET MAIN SCORE
 
for (var m:Number = 0; m <= 3;) {
scoreArray[4]+=scoreArray[m]
++m;
}
 
function RoundScore(){
 
for (var i:Number = 0; i <= 4;) {
 
ScoreH = Math.floor(scoreArray[i]/3600000);  
remaining = scoreArray[i]-(ScoreH*3600000);
//minutes
ScoreM = Math.floor(remaining/60000);
remaining = remaining-(ScoreM*60000);
//seconds
ScoreS = Math.floor(remaining/1000);
remaining = remaining-(ScoreS*1000);
//hundredths
ScoreH = Math.floor(remaining/10);
 
 
if (ScoreM<10) {
ScMins = "0"+ScoreM.toString();
} else {
ScMins = ScoreM.toString();
}
if (ScoreS<10) {
ScSecs = "0"+ScoreS.toString();
} else {
ScSecs = ScoreS.toString();
}
if (ScoreH<10) {
ScHunds = "0"+ScoreH.toString();
} else {
ScHunds = ScoreH.toString();
}
 
if(i==0)(Round1Sc=ScMins+":"+ScSecs+":"+ScHunds);
if(i==1)(Round2Sc=ScMins+":"+ScSecs+":"+ScHunds);
if(i==2)(Round3Sc=ScMins+":"+ScSecs+":"+ScHunds);
if(i==3){Round4Sc=ScMins+":"+ScSecs+":"+ScHunds};
if(i==4){PlayerSc=ScMins+":"+ScSecs+":"+ScHunds;}//MAIN SCORE
 
++i;
}
 
PScore.text=PlayerSc;//MAIN SCORE
Round1Score.text=Round1Sc;
Round2Score.text=Round2Sc;
Round3Score.text=Round3Sc;
Round4Score.text=Round4Sc;
}
 
RoundScore();
 
//////////////////////////////////////////////////
 
 
////ENTERING THE SCORE INTO DATABASE
 
//Define the Score Variable here
score = PScore.text;
 
 
//Edit this to destination after score is submitted.
//It currently just Disables the submit button.
function submitcomplete() {
TrackInfo.gotoAndStop(12);
	
 
}
 
//Here is the function to submitscore. DO NOT CHANGE.
function submitscore() {
	//New Variables to be Loaded
	var anticheat:LoadVars = new LoadVars();
	//Defining which Variables will be Loaded
	anticheat.score = score;
	anticheat.username = username;
	anticheat.action = 'anticheat';
	//Function when Data is Loaded
	anticheat.onLoad = function () {
		//Defining Echoed Variables
		chkscore = anticheat.chkscore
		chkusername = anticheat.chkusername
		//Checking if Data from PHP Matches Original Data
		if(score != anticheat.chkscore || username != anticheat.chkusername) {
			//Doesn't Match. Therefore Cheating.
			status = "Cheating";
		} else {
			//Does Match. Carry on.
			//New Set of Variables to be Loaded
			var subscore:LoadVars = new LoadVars();
			//Variables to be Loaded
			subscore.score = score;
			subscore.username = username;
			subscore.action = 'sendscore';
			//Function when Variables are Loaded
			subscore.onLoad = function() {
				//Change Status to whatever PHP Defined
				status = subscore.status;
				//Submition Completed. Function once done.
				//You Can define this at the top of this script
				submitcomplete();
			}
			//Load Variables to PHP
			//The Null and Random Number makes it so the computer doesn't rememer past uses.
			subscore.sendAndLoad("hsfuncs.php?null="+random(99999), subscore, "POST");
		}
	}
	//Load Variables to PHP
	//The Null and Random Number makes it so the computer doesn't rememer past uses.
	anticheat.sendAndLoad("hsfuncs.php?null="+random(99999), anticheat, "POST");
}
Open in New Window Select All

Answer : How do I add a lap time to a Mysql database in a flash game using PHP

It'd make life much easier if you just dealt with it in milliseconds, and only convert it to the time format when you need to display it to the user.  There are loads of scripts for doing the converting ready for you to use:
http://www.google.co.uk/search?hl=en&safe=off&ei=sdiMSe6NMomt-gacv-mdCw&sa=X&oi=spell&resnum=1&ct=result&cd=1&q=actionscript+2+milliseconds+to+time&spell=1


If the MySQL can't be changed, then you'll need to find out exactly what format it wants, as there's a little choice:
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-types.html

Once you know what it's expecting, then use the conversion scripts above to get it ready to be sent.
Random Solutions  
 
programming4us programming4us