Groups | Blog | Home
all groups > flash data integration > september 2005 >

flash data integration : Highscore display inside flash game using php and MYSQL


ChuckyLeFrek
9/26/2005 4:15:45 PM
I am trying to create a top ten highscore table inside my flash game using PHP
and MYSQL.

My problem is I am not sure how to get the data into Flash.

My database is called "mkhighscores"
The table is called "highscores_tb"

The fields are as follows:

id INT NOT NULL AUTO INCREMENT PRIMARY
game_id INT(4) NOT NULL
name VARCHAR(15) NOT NULL
score INT(15) NOT NULL

I have set the database up so it will hold highscores for more than one game
hence the game_id field

I am not sure how the PHP file will send the required data to Flash

I have read alot of tutorials today and realise that Flash must use the load
command to call the PHP page

e.g LoadObj.load("http://www.blahblah.com/highscores.php?game_id=2)

This will call the PHP page. I guess the PHP page will run a query but how
does it return the results to Flash?

And what format are the results returned to Flash?

Apologies if this is a bit muddled but I am trying to get to grips with a few
technologies at once. I do not want to use an off the shelf solution hence I am
trying to work it all out (with your help)

Thanks

Paul
ChuckyLeFrek
9/26/2005 5:20:59 PM
This may make things clearer

Here is my PHP code (I have replaced the username and password for obvious
reasons)

<?php
echo "<center>";
// set your infomation.
$dbhost='localhost';
$dbusername='username';
$dbuserpass='password';
$dbname='mkhighscores';

// connect to the mysql database server.
mysql_connect ($dbhost, $dbusername, $dbuserpass);

if (!mysql_select_db($dbname))
die(mysql_error());



$game = $_GET['game'];
$query = " SELECT game_id,name,score FROM highscores_tb WHERE game_id =
'$game' " .
" ORDER BY score DESC LIMIT 0, 10";
$result = mysql_query($query) or die('Error, query failed');

echo $result;

?>


From my Flash movie I have the following code:

Loaded_txt.text = "Loading";

LoadVarsObj = new LoadVars();

LoadVarsObj.onLoad = function() {
Loaded_txt.text = "Loaded";

}

LoadVarsObj.load("http://www.mediakitchen.co.uk/highscore2.php?game=1");

Basically I was hoping the above would result in my flash movie receiving the
top ten scores in some form or other.

Any help would be really appreciated

Paul
AddThis Social Bookmark Button