| | |
Connection problem
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Hi,
I have a small problem I have a flash game SWF file not the fla and it sends and recieves values from a PHP file send - update and recieve is INIT
Great except the person who gave me the SWF and PHP file did not tell me how to set up the database If I was to post the code could someone tell me the table layout to wright with PHP My Admin?
I know its only a small database we are talking 4 or 5 objects in 1 table but I just cant get my head around the code not knowing PHP
Cheers
Kev
I have a small problem I have a flash game SWF file not the fla and it sends and recieves values from a PHP file send - update and recieve is INIT
Great except the person who gave me the SWF and PHP file did not tell me how to set up the database If I was to post the code could someone tell me the table layout to wright with PHP My Admin?
I know its only a small database we are talking 4 or 5 objects in 1 table but I just cant get my head around the code not knowing PHP
Cheers
Kev
[PHP]<?
if ($command=="init"){
$link = @mysql_connect("localhost", "username", "password");
if (!$link){
print "&message=Error connecting to database";
exit;
}
if (!@mysql_select_db("kevinsmi_game")){
print "&message=Couldn't select database";
exit;
}
$players = "";
$scores = "";
$distances = "";
$victims = "";
$innerquery = "SELECT * FROM game ORDER BY scores DESC";
$innerresult = @mysql_query($innerquery);
$numPlayers=mysql_num_rows($innerresult);
for($loop=0;$loop<$numPlayers; $loop++) {
$newPlayer = mysql_result($innerresult,$loop,"players");
$newScore = mysql_result($innerresult,$loop,"scores");
$newDistance = mysql_result($innerresult,$loop,"distances");
$newVictim = mysql_result($innerresult,$loop,"victims");
$players = "$players<br>$newPlayer";
$scores = "$scores<br>$newScore";
$distances = "$distances<br>$newDistance";
$victims = "$victims<br>$newVictim";
}
printf("&players=%s", $players);
printf("&scores=%s", $scores);
printf("&distances=%s", $distances);
printf("&victims=%s", $victims);
mysql_close($link);
}
if ($command=="update"){
$link = @mysql_connect("localhost", "username", "password");
if (!$link){
print "&message=Error connecting to database";
exit;
}
if (!@mysql_select_db("game")){
print "&message=Couldn't select database";
exit;
}
$players = "";
$scores = "";
$query = "SELECT scores FROM game where players = '$name'";
$result = @mysql_query($query);
if(@mysql_num_rows($result)>0){
$oldScore = mysql_result($result,"scores");
if($score>$oldScore){
$query = "UPDATE game SET scores = '$score' where players = '$name'";
$result = @mysql_query($query);
}
}
else {
$query ="INSERT INTO game (players, scores, distances, victims) VALUES ('$name', '$score', '$distance', '$victim')";
$result = @mysql_query($query);
}
$innerquery = "SELECT * FROM game ORDER BY scores DESC";
$innerresult = @mysql_query($innerquery);
$numPlayers=mysql_num_rows($innerresult);
for($loop=0;$loop<$numPlayers; $loop++) {
$newPlayer = mysql_result($innerresult,$loop,"players");
$newScore = mysql_result($innerresult,$loop,"scores");
$newDistance = mysql_result($innerresult,$loop,"distances");
$newVictim = mysql_result($innerresult,$loop,"victims");
$players = "$players<br>$newPlayer";
$scores = "$scores<br>$newScore";
$distances = "$distances<br>$newDistance";
$victims = "$victims<br>$newVictim";
}
printf("&players=%s", $players);
printf("&scores=%s", $scores);
printf("&distances=%s", $distances);
printf("&victims=%s", $victims);
mysql_close($link);
}
?>[/PHP]
if ($command=="init"){
$link = @mysql_connect("localhost", "username", "password");
if (!$link){
print "&message=Error connecting to database";
exit;
}
if (!@mysql_select_db("kevinsmi_game")){
print "&message=Couldn't select database";
exit;
}
$players = "";
$scores = "";
$distances = "";
$victims = "";
$innerquery = "SELECT * FROM game ORDER BY scores DESC";
$innerresult = @mysql_query($innerquery);
$numPlayers=mysql_num_rows($innerresult);
for($loop=0;$loop<$numPlayers; $loop++) {
$newPlayer = mysql_result($innerresult,$loop,"players");
$newScore = mysql_result($innerresult,$loop,"scores");
$newDistance = mysql_result($innerresult,$loop,"distances");
$newVictim = mysql_result($innerresult,$loop,"victims");
$players = "$players<br>$newPlayer";
$scores = "$scores<br>$newScore";
$distances = "$distances<br>$newDistance";
$victims = "$victims<br>$newVictim";
}
printf("&players=%s", $players);
printf("&scores=%s", $scores);
printf("&distances=%s", $distances);
printf("&victims=%s", $victims);
mysql_close($link);
}
if ($command=="update"){
$link = @mysql_connect("localhost", "username", "password");
if (!$link){
print "&message=Error connecting to database";
exit;
}
if (!@mysql_select_db("game")){
print "&message=Couldn't select database";
exit;
}
$players = "";
$scores = "";
$query = "SELECT scores FROM game where players = '$name'";
$result = @mysql_query($query);
if(@mysql_num_rows($result)>0){
$oldScore = mysql_result($result,"scores");
if($score>$oldScore){
$query = "UPDATE game SET scores = '$score' where players = '$name'";
$result = @mysql_query($query);
}
}
else {
$query ="INSERT INTO game (players, scores, distances, victims) VALUES ('$name', '$score', '$distance', '$victim')";
$result = @mysql_query($query);
}
$innerquery = "SELECT * FROM game ORDER BY scores DESC";
$innerresult = @mysql_query($innerquery);
$numPlayers=mysql_num_rows($innerresult);
for($loop=0;$loop<$numPlayers; $loop++) {
$newPlayer = mysql_result($innerresult,$loop,"players");
$newScore = mysql_result($innerresult,$loop,"scores");
$newDistance = mysql_result($innerresult,$loop,"distances");
$newVictim = mysql_result($innerresult,$loop,"victims");
$players = "$players<br>$newPlayer";
$scores = "$scores<br>$newScore";
$distances = "$distances<br>$newDistance";
$victims = "$victims<br>$newVictim";
}
printf("&players=%s", $players);
printf("&scores=%s", $scores);
printf("&distances=%s", $distances);
printf("&victims=%s", $victims);
mysql_close($link);
}
?>[/PHP]
So... you realize you are trying to use 2 databases??
for command == "init" you have: mysql_select_db("kevinsmi_game")
for command == "update" you have mysql_select_db("game")
As far as the table:
db name: kevinsmi_game
table: game
field1: players
field2: scores
field3: distances
field4: victims
for command == "init" you have: mysql_select_db("kevinsmi_game")
for command == "update" you have mysql_select_db("game")
As far as the table:
db name: kevinsmi_game
table: game
field1: players
field2: scores
field3: distances
field4: victims
Cheers for that didn't notice I hadn't changed the second connection values :-)
I still can't get the thing to work though!! It is bugging me, I have the database set up as you have layed out above and that is how I have had it done from the start, but I just can't get it to read or write ot the database I have set up a simple table on a blank page and connected to the database through a simple table connection in dreamweaver and that works OK!!!!!!
I still can't get the thing to work though!! It is bugging me, I have the database set up as you have layed out above and that is how I have had it done from the start, but I just can't get it to read or write ot the database I have set up a simple table on a blank page and connected to the database through a simple table connection in dreamweaver and that works OK!!!!!!
![]() |
Similar Threads
- Vista and Connection Problem (Windows Vista and Windows 7)
- Yes. Yet another connection problem. (Viruses, Spyware and other Nasties)
- A7N8X-X MCP LAN Connection Problem (Windows NT / 2000 / XP)
- Internet Connection problem:Cable to modem to router to PC (Networking Hardware Configuration)
- AOL/router connection problem with msn messenger (Networking Hardware Configuration)
- Internet connection problem (Windows NT / 2000 / XP)
- Connection Problems (Networking Hardware Configuration)
Other Threads in the MySQL Forum
- Previous Thread: what to do with this .SQL script?
- Next Thread: MySQL Functions W/ Offline Languages
| Thread Tools | Search this Thread |
agplv3 alfresco amazon api artisticlicense aws bizspark breathalyzer camparingtocolumns changingprices cmg communityjournalism contentmanagement contractors copyright court crm data database design developer development distinct dui ec2 email enter enterprise eudora facebook form foss gartner gnu government gpl greenit groklaw groupware hiring hyperic images innerjoins insert ip joebrockmeier join journalism keyword keywords kickfire laptop law legal license licensing linux maintenance managing mariadb matchingcolumns metron microsoft microsoftexchange mindtouch mozilla multiple music mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opengovernment opensource oracle penelope php priceupdating query referencedesign reorderingcolumns resultset saas select sharepoint simpledb sourcecode spotify sugarcrm syntax techsupport thunderbird transparency virtualization





