Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 01-25-2005, 03:36 PM   #1
Registered User
Join Date: Jan 2005
Posts: 7
Question Storing dynamic number of variables

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
jcordina is offline   Reply With Quote
Old 01-26-2005, 04:04 AM   #2
Registered User
Join Date: Dec 2004
Posts: 112

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.
SmoothDime is offline   Reply With Quote
Old 01-26-2005, 08:47 AM   #3
Registered User
Join Date: Jan 2005
Posts: 7

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?
jcordina is offline   Reply With Quote
Old 01-26-2005, 09:59 AM   #4
Well known nobody
Join Date: Jul 2004
Posts: 818

You do know the number. If you're doing a mysql query, you can do something like:

PHP Code:
$result mysql_query($query);
$rows mysql_num_rows($result);
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:

PHP Code:
$query "SELECT * FROM myTable";
$result mysql_query($query);
$rows mysql_num_rows($result);
$i 0;
while (
$row mysql_fetch_assoc($result)){

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.
Laguana is offline   Reply With Quote
Old 01-26-2005, 02:23 PM   #5
I make out with chicks
Join Date: Oct 2002
Location: NYC
Posts: 1,586

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...
ActionScript Code:
var lv = new LoadVars(); lv.onData=function(dat){ var temp = dat.split("\\n"); for(var i in temp){ temp[i] = temp[i].split("|"); scope[temp[0]] = temp[1]; } } lv.load("scriptURL.php");
annexion is offline   Reply With Quote
Old 02-02-2005, 05:26 PM   #6
Registered User
Join Date: Feb 2005
Location: toronto
Posts: 2

one word... XML !
oledirty is offline   Reply With Quote
Old 02-02-2005, 06:33 PM   #7
Master of Nothing
Join Date: Dec 2002
Location: San Diego, CA
Posts: 2,468

Originally Posted by oledirty
one word... XML !
Fine for small amounts of data, when you get into the hundreds of nodes with childNodes, xml will choke.
freddycodes is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

All times are GMT. The time now is 01:34 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.