View Full Version : Money counter in php for a flash game
bunker
January 10th, 2004, 08:30 AM
Hi, what I would like to realize, is a flash game, a good example would be a slot machine, in which money of the player are retrieved by a database, and are updated as long as the game goes on. I have this example of slotmachine which i really like: game (http://www.flashkit.com/movies/Games/Full_Game_Source/Jackpot-Kasper_B-8916/index.php).
I am quite able to send the score to the database ( i am using Mysql) but i cannot manage to get the score back from the database, and tell to the database only to look on an user score. Please Help!!
bunker
January 13th, 2004, 03:37 PM
Is it possible that no one can help me?:(
norie
January 14th, 2004, 05:01 PM
SELECT `money` FROM tablename WHERE user='myusername'
bunker
January 16th, 2004, 03:55 AM
Could you be more specific? I don't know much about the interaction between flash and php. I tought to be able to send the data to the database, but i didn't manage to do this. I am studying how to do it, but it would be helpfull if you could show me the code so that I could understand.
Thanks in advance
norie
January 16th, 2004, 04:00 AM
well, how are you sending the in info to the DB? can you post some code (php/fla)?
bunker
January 16th, 2004, 04:06 AM
Of course, sorry!:h: The code I was trying to use comes from hotscript.com and is as follow:
< ?php
/*
// FLASH-HIGHSCORE by Daniel Lonn http://www.webknecht.net
// -------------------------------------------------------------------------------------
// let me know the changes if you modifie this script for
// a better db-perfomance: webknecht@webknecht.net
MYSQL: 2 tables needs to be created:
CREATE TABLE `user_online` (
`IP` varchar(15) NOT NULL default '',
`EXPIRE` int(10) unsigned default NULL,
`NAME` varchar(20) NOT NULL default '',
PRIMARY KEY (`NAME`),
KEY `IP` (`IP`)
)
CREATE TABLE `user_score` (
`IP` varchar(15) NOT NULL default '',
`NAME` varchar(20) NOT NULL default '',
`COUNTER` int(5) default NULL,
`DATE` varchar(12) NOT NULL default '',
PRIMARY KEY (`NAME`),
KEY `IP` (`IP`)
)
FLASH: you have to set dynamic textfields for every output-variable
i.e. to display 10 highscore-rows:
score0 ... score9
name0 ... name9
date0 ... date9
and flash variables for name and scores for a new player
you could send and load the highscore-values with:
loadVariablesNum(highscore.php?"+PlayersNameVariable+"&"+_PlayersScoreVariable+"&test="+random(number),Level or mc to load in, "POST");
i.e:
loadVariablesNum(highscore.php?"+name+"&"+_scores+"&test="+random(99999),0, "POST");
------------------------ VARS TO EDIT BEGIN ----------------------------------------------*/
$HOST = "xyz.de"; // hostname
$ID = "xyz"; // mySql-username
$PW = "xyz"; // mySql-password
$DB = "xyz"; // mySql-db-name
$time_range = 1800; // time-range in seconds to display online-users
$display = 10; // number of highscore-rows to display in flash
$score_min = 0; // '0' displays all scores || '1' displays only positive scores
// ------------------------ VARS TO EDIT END ------------------------------------------------
$tbl_user_online = "user_online";
$tbl_user_score = "user_score";
$date = date("d.m.Y");
$remote_addr = getenv("REMOTE_ADDR");
if($argv){
$post_vars=implode($argv,'');
$post_vars_array=explode("&",$post_vars);
$name = $post_vars_array[0];
$score = $post_vars_array[1];
}
$conn_id = mysql_connect($HOST,$ID,$PW);
mysql_select_db($DB,$conn_id);
// delete all old user-data from $tbl_user_online
mysql_query("DELETE FROM ".$tbl_user_online." WHERE EXPIRE < ".time()."");
if($score_min = 1){
// delete all user-data from $tbl_user_score with negative scores
mysql_query("DELETE FROM ".$tbl_user_score." WHERE COUNTER <= 0;");
}
// user exist?
$result3= mysql_query("SELECT count(*) FROM ".$tbl_user_score." where IP ='".$remote_addr."' and NAME = '".$name."'");
if(mysql_result($result3,0) == 0){
// user doesnt exist ==> new entry
mysql_query("INSERT INTO ".$tbl_user_online." (IP,NAME,EXPIRE) VALUES ('$remote_addr','$name','".(time()+$time_range)."');");
mysql_query("INSERT INTO ".$tbl_user_score." (IP,NAME,DATE,COUNTER) VALUES ('$remote_addr','$name','$date','$score');");
} else {
// user exist ==> update entry
mysql_query("UPDATE ".$tbl_user_online." SET EXPIRE = '".(time()+$time_range)."' WHERE IP ='".$remote_addr."'and NAME = '".$name."';");
mysql_query("UPDATE ".$tbl_user_score." SET DATE = '".$date."',COUNTER = '".$score."' WHERE IP ='".$remote_addr."'and NAME = '".$name."';" );
}
// select all user-data from $tbl_user_score to display in the flashmovie
$sql="select NAME,COUNTER,DATE from $tbl_user_score order by COUNTER desc";
$result=mysql_db_query($DB,$sql,$conn_id);
$count = mysql_numrows($result);
$i = 0;
while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
if($i < $display && $i < $count+1){
str_replace( "\n", "",$row[NAME]);
// flash output
print "&name$i=".$row[NAME]."&score$i=".$row[COUNTER]."&date$i=".$row[DATE];
$i++;
}
}
// count of all Users online
$online = mysql_query("SELECT count(*) FROM ".$tbl_user_online);
$gesamt = mysql_result($online,0);
// flash output
print "&online=".$gesamt;
? >
I hope it can be helpfull.
Thanks again!!!!!
:blush:
norie
January 16th, 2004, 04:28 AM
<?php
$HOST = "xyz.de"; // hostname
$ID = "xyz"; // mySql-username
$PW = "xyz"; // mySql-password
$DB = "xyz"; // mySql-db-name
$tbl_user_online = "user_online";
$tbl_user_score = "user_score";
$date = date("d.m.Y");
$link = mysql_connect($HOST,$ID,$PW) or die("Cannot connect: ".mysql_error());
mysql_select_db($DB,$conn_id) or die("Cannot Select DB: ".mysql_error());
$result = mysql_query("SELECT * FROM `$tbl_user_score` WHERE NAME='$name'",$link) or die("Query Failed" .mysql_error());
//i'm infering that COUNTER is the score.
$result_assoc = mysql_fetch_assoc($result);
print "&name=".$result_assoc['NAME']."&score=".$result_assoc["COUNTER"];
?>
use loadVars to get the score and name :)
bunker
January 26th, 2004, 05:06 PM
..... but I don't know how to load variables in to the flash file.....
Jubba
January 26th, 2004, 06:15 PM
http://www.kirupaforum.com/forums/showthread.php?s=&threadid=17604
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.