I Have a unique id generated for each record that I store into the database I want to pass that id to PHP and run a select statement against that and get a value back from the database and pass it back to flash, what is the best possible way to do it?
PS: I am using AS3
You have to call the php script which makes the sql connection and gets the value.
Here: http://livedocs.adobe.com/flex/2/langref/flash/net/URLLoader.html#includeExamplesSummary
The important part is here:
public function URLLoaderExample() {
var loader:URLLoader = new URLLoader();
configureListeners(loader);
var request:URLRequest = new URLRequest("urlLoaderExample.txt");
try {
loader.load(request);
} catch (error:Error) {
trace("Unable to load requested document.");
}
}
And here:
private function completeHandler(event:Event):void {
var loader:URLLoader = URLLoader(event.target);
trace("completeHandler: " + loader.data);
var vars:URLVariables = new URLVariables(loader.data);
trace("The answer is " + vars.answer);
}
In your php script you just have a print at the end:
<?php
$value = Select Statement to get that damn value out of the damn database
print $value;
?>
You will be able to read $value out of loader.data.
I don't really see your problem. What makes this really different from a client-side javascript invoking a server-side PHP? I mean, simply create a URLLoader
with the appropriate URLRequest
object (can also be a POST request), add an event handler for the COMPLETE event, and parse the returned document. I recommend XML, because that is easy to parse from AS3, but JSON and plain text should work as well.