heyder
07-15-2003, 12:45 PM
Wondering what I need to do to be able to use the DataGlue API, or if it even works with amfphp.
I've been able to get data back from php/mySql and populate a combobox but... I would like to figure out how to bind the data using DataGlue.
When I recieve the data back using amfphp is that considered a RecordSet or do I have to create a RecordSet in flash using
new RecordSet (colunmNames) or something
:confused:
freddycodes
07-15-2003, 01:51 PM
Depends on how you are getting the data, if you simple return the result of a query from your class, it is a recordset in flash.
Consider this class I use to get data from a people database in MySQL. Both getPeople and getPersonById will return a recordset to flash.
<?php
class People
{
var $db;
var $DBHOST = "localhost";
var $DBUSER = "********";
var $DBPASS = "*********";
var $DBNAME = "********";
function People()
{
$this->methodTable = array(
"getPeople" => array(
"description" => "Return a list of people from the database.",
"access" => "remote",
"roles" => "role, getPeople",
"arguments" => array ()),
"getPersonById" => array(
"description" => "Return a person detail",
"access" => "remote",
"roles" => "role, getPersonById",
"arguments" => array ("person_id"))
);
$this->db = mysql_connect($this->DBHOST, $this->DBUSER, $this->DBPASS);
mysql_select_db($this->DBNAME);
}
function getPeople() {
return mysql_query("SELECT person_id, person_name_first, person_name_last from person");
}
function getPersonById($person_id) {
return mysql_query("SELECT * from person WHERE person_id = '$person_id'");
}
}
?>
So if I call the getPeople method I get three fields back id firstname and lastname. Here is what my actionscript might look like.
#include "NetServices.as"
#include "NetDebug.as"
#include "DataGlue.as"
init = false;
if(defaultGateway == undefined) defaultGateway = "http://freddy/amf2/simpleGateway.php";
function connect() {
if(init == false) {
init = true;
NetServices.setDefaultGatewayURL(defaultGateway);
conn = NetServices.createGatewayConnection();
myservice = conn.getService("People", this);
myservice.getPeople();
}
}
connect();
function getPeople_Result(result) {
DataGlue.bindFormatStrings (myList, result, "#person_id# = #person_name_first# #person_name_last#");
}
stop();
AS you can probably see its fairly simple to use.
Or if you want to have labels and data in the listbox you can use the bindFormatFunction method like
#include "NetServices.as"
#include "NetDebug.as"
#include "DataGlue.as"
init = false;
if(defaultGateway == undefined) defaultGateway = "http://freddy/amf2/simpleGateway.php";
function connect() {
if(init == false) {
init = true;
NetServices.setDefaultGatewayURL(defaultGateway);
conn = NetServices.createGatewayConnection();
myservice = conn.getService("People", this);
myservice.getPeople();
}
}
connect();
function getPeople_Result(result) {
DataGlue.bindFormatFunction (myList, result, myCustomFunc);
}
function myCustomFunc ( record )
{
var myLabel = record.person_name_last + ", " + record.person_name_first;
return {label: myLabel, data: record.person_id};
}
stop();
heyder
07-15-2003, 07:53 PM
Sweet, thanks so much for the example code, I've just started playing around with this stuff so the more code samples I can get my hands on the better.:D
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.