View Full Version : Storing dynamic number of variables

01-25-2005, 03:36 PM
Hope this is the right forum to submit to. Sorry if this might seem trivial but its driving me crazy. I need to download a number of strings from a database to my flash movie through php. Php is doing a 'Select * from TableName' query and the resulting strings are returned to the flash movie inside different variables. I am using the LoadVars class to access these variables. Yet the number of results from the query can change. How can I store the results in my flash movie? Is there a way how to place the results in some dynamic structure for example arrays. Hope someone can help. Thanks

01-26-2005, 04:04 AM
just do something like this:


then in your AS you can loop through 10 times knowing the names of the variables and get their values that way you noob. jk.

01-26-2005, 08:47 AM
What If I do not know the maximum number. There might be a hundred or a thousand being passed back, I cannot write code for each and every variables no?

01-26-2005, 09:59 AM
You do know the number. If you're doing a mysql query, you can do something like:

$result = mysql_query($query);
$rows = mysql_num_rows($result);
echo "&numResults=".$rows."&"

which will echo the number of rows returned, and then as you iterate through the rows you use the iteration number along with the column name thing... for example:

$query = "SELECT * FROM myTable";
$result = mysql_query($query);
$rows = mysql_num_rows($result);
echo "&numResults=".$rows."&";
$i = 0;
while ($row = mysql_fetch_assoc($result)){
echo "&name".$i."=".$row['name']."&";
echo "&anotherfield".$i."=".$row['anotherfield']."&";

Then in flash you know how many rows there are, numResults, and you cycle through from 0 to numResults-1, where each result is stored in columnamenumber, so if you want the 5th "name" result, it would be name4. Hope that makes sense.

01-26-2005, 02:23 PM
You could just return your data in a delimited table format, and then parsing it will automatically take care of it.

For instance:

if your data looked like this...


Then you could use AS like this...

var lv = new LoadVars();
var temp = dat.split("\\n");
for(var i in temp){
temp[i] = temp[i].split("|");
scope[temp[0]] = temp[1];

02-02-2005, 05:26 PM
one word... XML !

02-02-2005, 06:33 PM
one word... XML !
Fine for small amounts of data, when you get into the hundreds of nodes with childNodes, xml will choke.