PDA

View Full Version : Send ID retrieve Field based on ID


burga
03-16-2011, 11:10 AM
First off, my project is in Flex 4, and uses PHP and an SQL database to submit and receive information, the submitting of data is working an I'm happy with it.
It currently uses the prototyped PHP script from flashbuilder (separate devs working on that aspect) and the ZendFramework)

However the retrieval is proving a little tricky.

Essentially I have a comboBox, which is searching my SQL database by name(one of my fields) using labelField and I have a changeHandler which then sends the ID of that element to my textArea, the textArea, should then be displaying another field from the element.

My Database structure:


dedicationID - unique auto-incremental field
RecipientName
RecipientEmail
SenderName
SenderEmail
Message

With the code I have currently, which i'll post at the bottom, I can search the db, and when I select an entry, all I get is the ID of the element in my textArea, instead of the Message which i'm trying to retrieve.

protected function comboBox_creationCompleteHandler(event:FlexEvent): void
{
getAllDedicationResult.token = dedicationService.getAllDedication();
}


protected function comboBox_changeHandler(event:IndexChangeEvent):voi d
{
textArea.text = textArea.text + comboBox.selectedIndex
}


protected function textArea_creationCompleteHandler(event:FlexEvent): void
{
getDedicationByIDResult.token = dedicationService.getDedicationByID(comboBox.selec tedIndex);

}

^ my functions



<s:ComboBox includeIn="home" x="31" y="94" id="comboBox" creationComplete="comboBox_creationCompleteHandler(event)" labelField="RecipientName"
change="comboBox_changeHandler(event)">
<s:AsyncListView list="{getAllDedicationResult.lastResult}"/>
</s:ComboBox>
<s:TextArea includeIn="home" x="686" y="168" id="textArea" creationComplete="textArea_creationCompleteHandler(event)" text="{getDedicationByIDResult.lastResult.Message}"/>

^ my MXML code


Ideally functionality wise, when an entry is selected it should go to a new state with 3 textAreas, each retrieving RecipientName, SenderName and Message respectively, all from the same ID.

And then one final aspect of my project I wish to implement, is a count() function, which adds a graphic for every entry that is in the database.

Thanks

mike007
03-16-2011, 01:27 PM
So what I do to accomplish this is I added my result from the mySQL call to an ArrayCollection. Then everything is binded to the arraycollectoin. The you just reference the selectedIndex of that combobox in the arraycollection, and done. You have all the entries for that item/object.

burga
03-16-2011, 02:21 PM
When you say added your result from the mySQL, do you mean a service call? as in the following:

protected function getAllDedication():void
{
getAllDedicationResult2.token = dedicationService.getAllDedication();
}

How would i bind that in an ArrayCollection, and have the text area pull the value from there and the comboBox.


Also, as you seemed clued up with the SQL side of things, how would i use a count function to count my SQL entries and to place a graphic/mc/sprite inside one of my components for each SQL entry?

Thanks for the help

mike007
03-16-2011, 02:32 PM
For the count thing, you could add another field for mySQL with a link to the image.

I write my own PHP and do not use the premade service. I return my results in an XML. But you just create a result event for the service call and set your arraycollection to the event object.


[Bindable]
private var samplegridData:ArrayCollection = new ArrayCollection();

protected function sampleData_resultHandler(event:ResultEvent):void
{
samplegridData = event.result.item.items;
}


When you say added your result from the mySQL, do you mean a service call? as in the following:

protected function getAllDedication():void
{
getAllDedicationResult2.token = dedicationService.getAllDedication();
}

How would i bind that in an ArrayCollection, and have the text area pull the value from there and the comboBox.


Also, as you seemed clued up with the SQL side of things, how would i use a count function to count my SQL entries and to place a graphic/mc/sprite inside one of my components for each SQL entry?

Thanks for the help

burga
03-16-2011, 03:04 PM
The SQL route for the images i don't think is very viable, as in the same app, a person will add entries to the DB via a page, which basically contains 2 names, 2 emails and a message, which then emails a link to the recipient where they return to the site with a unique url to view the message.

And i'm really struggling with this still, even after all the info you've given me.

If you could assist me some more, here is all my code:

<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.rpc.events.ResultEvent;

import spark.events.IndexChangeEvent;

import valueObjects.Dedication;


protected function comboBox_creationCompleteHandler(event:FlexEvent): void
{
getAllDedicationResult.token = dedicationService.getAllDedication();
}


protected function comboBox_changeHandler(event:IndexChangeEvent):voi d
{
textArea.text = textArea.text + comboBox.selectedIndex
}


protected function textArea_creationCompleteHandler(event:FlexEvent): void
{
getDedicationByIDResult.token = dedicationService.getDedicationByID(comboBox.selec tedIndex);
}


protected function count():void
{
countResult.token = dedicationService.count();
}

]]>
</fx:Script>

<s:states>
<s:State name="home"/>
<s:State name="dedicate"/>
<s:State name="dedication"/>
</s:states>

<fx:Declarations>
<s:CallResponder id="getAllDedicationResult"/>
<dedicationservice:DedicationService id="dedicationService" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
<s:CallResponder id="getDedicationByIDResult"/>
<s:CallResponder id="countResult"/>
</fx:Declarations>

<fx:DesignLayer d:id="2" d:userLabel="Layer 1">
<components:Search x="23" y="78" >
</components:Search>
<s:RichText ai:aa="2" color="#808080" columnCount="1" fontFamily="Adobe Garamond Pro Bold" fontSize="36" fontWeight="bold" height="35" d:id="5" kerning="on" tabStops="S36 S72 S108 S144 S180 S216 S252 S288 S324 S360 S396 S432 S468 S504 S540 S576 S612 S648 S684 S720 S756 S792" text="This mothers day dedicate to the mothers of the world" d:userLabel="This mothers day dedicate to the mothers of the wo..." flm:variant="3" whiteSpaceCollapse="preserve" width="824" x="22" y="24"/>
<components:Tree x="137" y="78">
</components:Tree>
<Form:DedicateForm id="dedicate1" includeIn="dedicate" x="647" y="77"/>
<components:Dedication id="dedication1" includeIn="dedication" x="647" y="77">
</components:Dedication>
</fx:DesignLayer>

<s:Button x="880" y="609" label="dedicate" click="currentState='dedicate'"/>

<s:ComboBox includeIn="home" x="31" y="94" id="comboBox" creationComplete="comboBox_creationCompleteHandler(event)" labelField="RecipientName"
change="comboBox_changeHandler(event)">
<s:AsyncListView list="{getAllDedicationResult.lastResult}"/>
</s:ComboBox>

<s:TextArea includeIn="home" editable="false" x="686" y="168" id="textArea" creationComplete="textArea_creationCompleteHandler(event)" text="{getDedicationByIDResult.lastResult.Message}"/>

</s:Application>