4 Replies Latest reply on Nov 22, 2006 12:54 PM by ntsiii

    Help on datagrid from XML

    rambo3
      Well i realy cant solve this problem.
      I have php file that reads mysql, and i am trying do display it in datagrid :

      checklogin.php:
      /*********************************************************/
      $details = "<xml>";
      while($row = mysql_fetch_assoc($checkuser))
      {
      $details .= "<user>";
      $details .= "<ID><![CDATA[".$row['ID']."]]></ID>";
      $details .= "<Fornamn><![CDATA[".$row['firstname']."]]></Fornamn>";
      $details .= "<Efternamn><![CDATA[".$row['lastname']."]]></Efternamn>";
      $details .= "<Postadress><![CDATA[".$row['postaddress']."]]></Postadress>";
      $details .= "<Stad><![CDATA[".$row['city']."]]></Stad>";
      $details .= "<Land><![CDATA[".$row['country']."]]></Land>";
      $details .= "<Telefon><![CDATA[".$row['telephone']."]]></Telefon>";
      $details .= "<Epost><![CDATA[".$row['ID']."]]></Epost>";
      $details .= "</user>";
      }
      $details .="</xml>";

      /***************************************************************************************** ************/
      And in flex:

      private function loadDBusers():void{
      //deleted code it works
      DBconnect.url=("checklogin.php");
      DBconnect.resultFormat="text";
      DBconnect.addEventListener(ResultEvent.RESULT, dbUsersLoaded);
      DBconnect.send();

      }

      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!The problem function; !!!!!!!!!!!!!!!!!!!!!!!!!
      private function dbUsersLoaded(evtObj:Event):void{

      // i tryed both the comented out and not comented out code .The first displays some wird info that is not datagrid but arraycollection object info

      var tableData:ArrayCollection = new ArrayCollection(ArrayUtil.toArray(mx.utils.XMLUtil.createXMLDocument(DBconnect.lastResult .toString())) );
      //databaseusers.dataProvider = tableData;


      ################################### Method 2 ##################################################
      var xDBlist:XML = new XML(DBconnect.lastResult.toString());
      var dbArrayC:ArrayCollection = new ArrayCollection(ArrayUtil.toArray(xDBlist.user));
      databaseusers.dataProvider=dbArrayC;
      }

      So problem is casting object from String -> XML -> Array -> Arraycollection