views:

26

answers:

1

I'm trying to wrap my brain around getting data into my project in a way that I can use.. I want to use MySQL & PHP my Flashbuilder app and I'm not populating a datagrid so......

For simplicities sake, In my database table I have 3 columns "ID, Title & Content".
I want to use this to populate the different states in my flashbuilder project.

Normally in a web page I could say in the sql statement "SELECT * FROM table WHERE ID = 1" to get the first row of info and I could put my Title and Content where I want them on my page I can change the query to "SELECT * FROM table WHERE ID = 2" to populate page 2 to get it's title and content.

In flashbuilder it all on the same page and I'm not understanding how to populate a singular text field for a title or content area with a single field from the database.

it seems all the examples on the web are basically for datagrids. Can someone please help me out.

Thanks

Dave

A: 

I'll try to help.

You have the database table (ID, Title, Content).

Go ahead and create a web service in PHP that will ping the database and retrieve the data. I don't know much about PHP, so can't help with specifics. If possible, I recommend using something like AMFPHP or ZendAMF to transfer data back and forth between Flex and PHP.

In Flex, you can retrieve the data using RemoteObject, WebService, or HTTPService. You'll get the data back somehow. For the purposes of this sample, I'll assume you're using a form of AMF and have an array of value objects.

Each object contains an ID, title, and content property, representing a single row in your database table.

Now, what do you do with that array? It would be odd to try to display a collection of data in a single text input. Let's pretend you want to create a form to edit the first item:

    <Form>
<formItem label="title">
 <textInput id="titleInput" text="{resultsFromPHP[0].title}" />
</formitem>
<formItem label="content">
 <textInput id="contentInput" text="{resultsFromPHP[0].content}" />
</formitem>
<formItem >
 <button label="Process Input" click="processInput()" />
</formitem>
</form>

So, you have a form that allows for inputs, and has a button. Just write the click handler:

protected function processInput():void{
 resultsFromPHP[0].content = contentInput.text
 resultsFromPHP[0].title = titleInput.text
 // call other PHP Service to update data
}

Does that help?

This was psuedo code I wrote in the browser and will most likely need tweaking to compile.

www.Flextras.com
Well I did get something to work and I appreciate you putting me on the path! I am getting some binding errors "Data binding will not be able to detect changes when using square bracket operator. For Array, please use ArrayCollection.getItemAt() instead."<code>protected function fetchDB(event:FlexEvent):void{ getResults.token = pagesService.getAllPages(); }<s:Label x="10" y="10" width="300" height="100" creationComplete="fetchDB(event)" text.Page1="{getResults.lastResult[0].title}" fontSize="24" text.Page2="{getResults.lastResult[1].title}"/></code>
dmschenk
Are you getting errors or warnings? I recommend saving getResults.lastResults into a local variable as opposed to accessing your service directly. Do that in your result handler. Then just modify your code as the warning suggests: text.Page1="{savedResult.getItemAt(0).title}"
www.Flextras.com
you are correct... I'm getting warnings. I'll give it a shot. Thanks
dmschenk