PHPBuilder - Using PHP and MySQL with Flash Page 7



RSS Twitter
Articles Databases

Using PHP and MySQL with Flash - Page 7

by: Jeffrey F. Hill
|
December 14, 2001

Loading the Variables

PHP used the Loading Variables Part (Load.php)
The load variables part is not important the first time a user enters the room. It does become important when a user moves the objects then returns to the room at a later time. This is what loads them all into the same place as when the user left. It also loads a comment that the user can optionally leave. Here's what the basic script looks like. Again it is strongly recommended to follow along by also reading the php script. They are commented in much more detail.


$result = mysql_query("SELECT * FROM $table WHERE Name = '$Name'");
     ##This sets the variables from the Database
     $Comment = mysql_result($result,0,"Comment");
     $Object1 = mysql_result($result,0,"Object1");
     $Object2 = mysql_result($result,0,"Object2");
     $Object3 = mysql_result($result,0,"Object3");

if ($Comment == "") {
    $Comment = "Hello $Name";
}
#This next bit prints out the values of the Comment and the positions of 
the three objects whose properties you want to save. This is the line that
Flash will read into the movie.

print "Comment=$Comment&$Object1$Object2$Object3";

The first line of code just selects the record in the database where the Name that the person logged in as matches the name in the database. After this, each column in the result record set is set to a variable. This basically just extracts the result you got from the query and puts it into variables that you can use. The if statement is necessary to make sure that the Comment variable contains some value. This will be explained later. The last line of code prints the results back to Flash. Notice how Object1, Object2, and Object3 are not separated by the & symbol. This is because the & symbols already exist in the database -- when you update the database these are included. Not necessary but just makes it easier.

« Previous Page
1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
9
Next Page »

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Jeffrey F. Hill

Comment:



Comment:

(Maximum characters: 1200). You have characters left.