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

Hi,
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
SmoothDime
Registered User
 
Join Date: Dec 2004
Posts: 112
Default

just do something like this:

numVars=10&var0=value0&var1=value1&var2=value2...

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
jcordina
Registered User
 
Join Date: Jan 2005
Posts: 7
Default

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
Laguana
Well known nobody
 
Join Date: Jul 2004
Posts: 818
Default

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);
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:

PHP Code:
$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']."&";
$i++;

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
annexion
I make out with chicks
 
Join Date: Oct 2002
Location: NYC
Posts: 1,586
Default

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...

varName|varValue
varName|varValue
varName|varValue
varName|varValue
varName|varValue
varName|varValue

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");
__________________
www.perpetuated.com
annexion is offline   Reply With Quote
Old 02-02-2005, 05:26 PM   #6
oledirty
Registered User
 
Join Date: Feb 2005
Location: toronto
Posts: 2
Default

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

Quote:
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
Reply


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 03:43 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.