tags:

views:

200

answers:

2

i am trying to load a variable through php from a sql database but i get nothing

here is the code

var Idfield;
var loader:URLLoader = new URLLoader();
// data will come as URL encoded variables
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(new URLRequest("pull.php"));
loader.addEventListener(Event.COMPLETE,dataload);           
function dataload(e:Event){
 Idfield =e.target.data["id"];
 trace(Idfield);
}

here is the php code

   $query = "SELECT max(id) from $tablename";
    $result = mysql_query($query) 
  or die("no rows selected");
    $row = mysql_fetch_row($result); // extracts one row
    echo  "id=$row[0]";
A: 

well for one thing, you need to add your event listener before you actually call load().

When you say you get nothing, what do you mean?

you can also listen for an error event and dump out any error messages from there.

HTH

Ryan Guill
if i only use Idfield =e.target.data;if get the whole php when i do the trace
what do you mean you get the whole php? The script? The output of the script? We really need you to be more specific to be of much help.
Ryan Guill
sorry about that.. i get he whole php script back when i do the tracebut if i try Idfield =e.target.data["id"]; i get nothing back
if you are getting the script itself back, meaning the code, then that means that your php script is not being executed...If you browse to that script itself in your web-browser, what do you get?
Ryan Guill
i actually get the value.. its only through flash that am not getting anything back
i got it after changing echo "id=$row[0]"; thanks for the help though
+1  A: 

I believe the variables format expects the variables in the name=value format so try something like:

echo 'id=' . $row[0];
Stephen Caldwell
this doesn't work
Yea, you're right. That should have been a . for concatenation. Let me fix it.
Stephen Caldwell