4 Replies Latest reply on Aug 31, 2006 12:49 PM by CoolCountDracula

    Simple HTTPService that returns text

      I've searched through Google and the documentation for this but still can't seem to find what I want. Basically, I have a php file that takes some input, processes it, and returns text, I already know how to pass on data to the php file from flex, what I'm trying to do is get the text that the file returns and put it in a label in my flex app.

      So far, I have a function that the httpservice calls when the "result" event occurs, but so far, I still havn't found away to get the actual text that is returned, can anyone tell me how to get that text from the HTTPService?

      Just a note, I'm using the mxml form of the httpservice.
        • 1. Re: Simple HTTPService that returns text
          jmortimer Level 1
          The only thing is, your text that is returned from php has be in in xml format. So, print your result query out in XML first. And then parse through the xml in flex using something like this:

          <mx:List dataProvider="{httpServiceName.lastResult.XMLRootName.XMLResultSetName}" labelField="fieldName"/>

          I built a script that automatically parses any MySql query i throw at it into xml. There are some constrains you must follow while using it though.

          The calling script must have:
          $Query = some mysql query
          $queryName = "name you give it"; //this will also equal the XMLRootName
          $tableName = "name you give it"; //this will equal the XMLResultSetName and doesn't really mean the table you are querying, but rather a generic name you give to the results table.
          $Result = mysql_query( $Query ); //the $Query is simply the veriable that calls the actuall mysql query.
          include ("xmlParser.php"); //placed after the $Result statement.

          //create root node;
          $Return = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"."\n"."\n";
          $Return .= "<$queryName>"."\n";

          // process one row at a time
          while($row = mysql_fetch_assoc($Result)) {

          // add node for each row
          $Return .= " <$tableName>"."\n";

          // add a child node for each field
          foreach ($row as $fieldname => $fieldvalue) {

          $Return .= " <$fieldname>"."$fieldvalue"."</$fieldname>"."\n";

          } // foreach

          $Return .= " </$tableName>"."\n";
          } // while

          $Return .= "</$queryName>"."\n";


          Then use the dataProvider to display resutls in Flex.
          • 2. Re: Simple HTTPService that returns text
            Scriptor_of_Historium Level 1
            Thanks, so it's possible to output xml with php, and have flex be able to read that xml like any other xml data? If so, then that's pretty cool.
            • 3. Re: Simple HTTPService that returns text
              jmortimer Level 1
              Well php pushes out the xml only because you code it that way. it is a string, just like any other string. But using the script I made, I never have to create the strings manually again. I just have to call that script after my queries in the php scripts that flex calls.

              It is great. The only issue I found with using my script over and over with different querys and result sets: I have to use actionscript to concatenate data-sets post query, or format data in flex. For example, i used to use php's date function to format the date stamp. So instead of being 2006-08-15 12:34:41, I would use php to export Aug, 15. Or I used to use php to do something like this <fullName>$firstName + $lastName</fullName> and then flex wouldn't need to worry about it. But now, i just use actionscript within flex. Not too big of a deal.

              Good luck.
              • 4. Re: Simple HTTPService that returns text
                wat if i want to get large amounts of data from php. like all language strings. which temselves are more than 200 kb bundle that with xml and it easily floats above 500kb.

                httpservice has ways to get array data.

                how do i return that from php and use that in result handler.