1

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]";
hitek
  • 372
  • 1
  • 17
  • 33

2 Answers2

1

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

echo 'id=' . $row[0];
Stephen Caldwell
  • 5,044
  • 1
  • 17
  • 10
0

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
  • 13,558
  • 4
  • 37
  • 48
  • if i only use Idfield =e.target.data; if get the whole php when i do the trace – hitek Feb 05 '09 at 20:18
  • 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 Feb 05 '09 at 20:32
  • sorry about that.. i get he whole php script back when i do the trace but if i try Idfield =e.target.data["id"]; i get nothing back – hitek Feb 05 '09 at 20:35
  • 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 Feb 05 '09 at 20:37
  • i actually get the value.. its only through flash that am not getting anything back – hitek Feb 05 '09 at 20:44
  • i got it after changing echo "id=$row[0]"; thanks for the help though – hitek Feb 05 '09 at 20:56