hey there people, i was just wondering how to do this. I want my table from the database in an array in flash. What is the concept of this, should i send a string with each variable/object and have flash sort it out into a array or can you just let php make the array and send that over?
Could you guys help me out with this, or point me to a tutorial (have looked but cant find the right one)?
I would either
create a txt file in PHP containing a string with each variable/object separated by a comma(or any sign )so can split the string into an array once loaded into Flash
Depending on what your end means are; I would populate an array in PHP using a delimination, as suggested in the previous post and send that data over to flash and stuff it in a variable. Then you can extropolate it in flash using whatever method you choose. Need deatils on how to do this?
Here is an example using PHP, MySql, and the loadVars.onLoad method
Here is the PHP
<?
//link up to mysql
$username="your username";
$password="your password";
$database="glasses";
$link = @mysql_connect("localhost",$username,$password);
//prefix variable for flash interpolation
print "output=";
mysql_select_db($database, $link) or die ("Unable to select database");
// Request the text of all the glasses
$result = @mysql_query("SELECT ID, name FROM
glass");
// Display the text of each Shotglass
$num_rows = mysql_num_rows($result);
while ( $row = mysql_fetch_array($result) ) {
$glassid = $row["ID"];
$glasstext = $row["name"];
// Variable to send to flash notice the "|" that delimites the values
print "$glasstext|";
}
?>
Here is the flash
// create new load vars
varReceiver = new LoadVars();
// loads the variables, this must be a url
varReceiver.load("http://structure.myftp.org/flash/dev/glassesLoadTest.php");
//assisgns the callback funtion
varReceiver.onLoad = handleLoad;
//defines the callback function and proccess whatever you want to do with the variables
function handleLoad (success) {
if (success) {
trace(this.output);
}else{
trace("no variables were found");
}
}
Ok i have got this working now; getting data from the database in myArray=bla|bla2|bla3 form and converting it to an array with the split function. Now for another more difficult part. How do i get a twodimensional array?
I have these fields in my database: name, age, place
and I want to get this array (with a loop so if there are more persons in it the array will be bigger):