PDA

View Full Version : populate listBox w/variables from PHP/mySQL


irongrip
07-10-2003, 07:46 PM
I'm trying to populate a UI listBox with the variables that are returned from a query to a mySQL database through PHP, but no matter what I do, the variables are returned to Flash correctly, but nothing at all happens with the listBox.Please help me if you can. My source code is below:


//Creates two new LoadVars objects, one for sending variables, and one for recieving.
var search = new LoadVars();
var searchResults = new LoadVars();
function searchDB(){
//Checks to make sure there are search parameters entered.
if (lName.text == "" && fName.text == "" && nId.text == "") {
_root.statusMsg.text = "Please enter more search parameters.";
} else {
search.FirstName=_root.fName.text;
search.LastName=_root.lName.text;
search.NamesId=_root.nId.text;
search.sendAndLoad("retrieveMM.php",searchResults,"POST");
searchResults.onLoad=function(success){
_root.successStatus.text=success;
_root.statusMsg.text = "Records are loaded.";
_root.searchStatus.text=searchResults;
if(success){
var itemLabel;
lbxAddressDisplay.removeAll();
lbxAddressDisplay.addItem("F Name:", 1);
for(i=0; i<searchResults.n; i++){
itemLabel = searchResults["LastName"+i] + ", " + searchResults["FirstName"+i];
itemLabel +="\t" + searchResults["Company"+i] + "\t" + searchResults["EMailAddress"+i];
lbxAddressDisplay.addItem(
itemLabel,
{NamesId:searchResults
["NamesId"+i],
LastName:searchResults["LastName"+i],
Company:searchResults["Company"+i],
EMailAddress:searchResults["EMailAddress"+i]
}
);

}
}
}
}
}

CyanBlue
07-11-2003, 02:27 AM
Howdy and Welcome... ;)

Please use code formatting (http://www.actionscript.org/forums/misc.php3?action=bbcode#buttons) to make the code readable... Your code is not so easy to read... :(

I just want to mention a couple of things...


You have this line..._root.searchStatus.text = searchResults;Change it to this..._root.searchStatus.text = unescape(searchResults);and tell us what you see within the '_root.searchStatus' text field??? I want to see the output from the PHP script...


This code...for (i = 0; i < searchResults.n; i++)Change it to this...for (i = 0; i < Number(searchResults.n); i++)Everything that are coming from outside of the Flash are generally considered as string, so you might need to cast it to get the for loop working as it is supposed to be...

irongrip
07-13-2003, 04:02 AM
Here's the output from the PHP script.( The contents of the searchStatus text box). Thanks for your help. It's actually one line, but I thought it might be simpler to seperate it at the ampersands for you, seeing as how they're the delimiters anyway. This is the result of calling one record from the database by searching the record ID("NamesId").

LastEditedBy0=&
LastEditDate0=20030614004725&
AddedBy0=&
DateAdded0=2003%2D05%2D01&
SecurityLevel0=5&
Password0=member&
CompleteName0=&
DateLastDuesPayment0=2003%2D05%2D01&
LatestMembershipYear0=2003&
MembershipType0=&
NameSource0=&
TertiaryURL0=&
SecondaryURL0=&
PrimaryURL0=www%2Eanyoldco%2Ecom&
OtherPhone0=&
FaxPhone0=&
CellPhone0=&
BusinessPhone0=623%2D531%2D9615&
EMailAddress20=&
EMailAddress0=stranger3710%40netscape%2Enet&
Company0=Irongrip%20Design%2C%20Inc%2E&
ZipCode0=85327&
State0=AZ&
City0=Buckeye&
Address20=&
Address10=1234%20Any%20Street&
NameSuffix0=&
LastName0=Hinkley&
MiddleNameInitial0=&
FirstName0=Marvin&
Salutation0=Mr%2E&
NamesType0=Type&
Active0=1&
NamesId0=1&
n=1

CyanBlue
07-13-2003, 04:37 AM
Well... I just did a quick test with given data and it does work on my end... You might need to give me some more information if this doesn't work for you... ;)

irongrip
07-14-2003, 01:20 PM
Once again, thank you for all the help you've given me. It's good to be in contact with someone with a bit of experience. I've been learning actionscript, PHP, and the bit of Java that I know through tutorials, luck, and brute-determined code analysis.

Here's the thing. I've tested my source code after applying your modifications, and for all intents and purposes, it should've worked. I was thinking it might simply be a matter of building a parsing routine for the PHP returned string. Seeing as it's just a string, I thought I might have to seperate it at the delimiters and the "equals" signs, and form newly defined variables so that there would be actual name-value pairs for Flash to work with. But in your version of retrieveMM.php, you echoed a string, and that worked just fine. So I started to wonder if perhaps there might be something amiss with my addItem() method call itself. I ran a simple test with a seperate Flash movie as a control group, defining a specific label parameter in the addItem() method in both movies. The code:
_root.lbxAddressDisplay.addItem("marvin");

In the control group movie, which I made from scratch, not copying in any of my previously written code, the listBox diplayed one label, "marvin", with no difficulty. However, in my original movie, the exact same code did nothing. Can you think of any reason that a simple addItem call would function in one movie, but not in the other outside of a syntax error, or perhaps Flash breaking or escaping the pertinent line of code prematurely?

freddycodes
07-14-2003, 01:43 PM
You know sometimes components get screwed up for one reason or another, try removing the listbox component from your library and then drag new copy of the list box to your stage from the components panel. Also you might want to start looking at different transport mechanisms for your data transport. You seem to be passing a lot of information over, and it also seems to have some sort of structure. You may want to start looking at XML or possibly even PHP remoting to get your data into flash.

irongrip
07-14-2003, 02:22 PM
Thanks CyanBlue, FreddyCodes! It turns out that the problem was indeed the Flash UI listBox component after all. Problem solved! Mission Accomplished! If either of you could ever use any help, or are ever in the Buckeye/Phoenix, Arizona area, let me know!
IronGrip

freddycodes
07-14-2003, 02:25 PM
I can't even tell you how many times that has screwed me up. I am not sure how the components get corrupted, they just do.


If either of you could ever use any help, or are ever in the Buckeye/Phoenix, Arizona area, let me know!


Can't imagine visiting Arizona this time of year. But heck you are probably climatized (s/p?).

irongrip
07-14-2003, 03:50 PM
After so many years in Arizona, I regularly breath super-heated desert dust. But as they say, it's a dry heat.

freddycodes
07-14-2003, 04:40 PM
Keep telling yourself that, it will help ease the pain.;)

CyanBlue
07-14-2003, 05:06 PM
freddycodes back to AS.org... :) Where have you been man???

FUI Component was causing problem??? Hm... So, you just swap it with the new copy and it is working fine afterwards??? I haven't had this sort of experience myself... FUI Component has been good to me so far... But then, I can imagine how painful it will be when I had to modify the codes in the FUI Component and have to replace it because it is not working properly... :D

Arizona??? Heck... I ain't going near that place... You just made me sweat more just by the sound of it... :p

freddycodes
07-14-2003, 05:09 PM
Been busy with work stuff, actually not just the FUIComponent for me, but the whole shebang gets corrupted sometimes.

CyanBlue
07-14-2003, 05:21 PM
Being busy is good... Glad to hear nothing bad happened while you were gone(?)... Had heard some bad news around hear recently... People getting sick and stuff...

Hm... I guess I have to use components more frequently to see that happening... Judging by the tone of your voice, you are blaming MM for that, aren't you??? :p

freddycodes
07-14-2003, 05:25 PM
Well put it this way, last week I dropped 99 dollars on the DRK volume 1, so I could see what extra features the MM datagrid had ove rthe one I created. I dragged it on the stage, and then none of the existing comboboxes in the movie worked. So I tried agai nand this time I chose not to replace existing items, and the datagrid didn't work. Movie got all mucked up.

Better documentation is what is needed.

CyanBlue
07-14-2003, 05:34 PM
Ouch... Well spent $99 it was then??? :p

Geez... How could that happen??? (Come to think of it, I think I had similar problems a while ago...)

Documentation... Yeah... No need to remind me again...
MM is real bad with that part... :(

freddycodes
07-14-2003, 05:41 PM
And actually the only thing I really found better with MM's grid than mine was the ability to add checkbox and combobox columns.

CyanBlue
07-14-2003, 06:24 PM
Ouch... That was it??? I am sure you can easily add them to the freddyGrid and you can sell it at a half price... I am sure that you don't have to worry about the work anymore... :)

freddycodes
07-14-2003, 06:25 PM
Right............................................. .................................................. ......

CyanBlue
07-14-2003, 06:30 PM
The only thing that is missing is the power of the marketing department, and actually you do have more advantage than MM since you know real people who can actually make use of this component... ;)