Bonjour, j'essaie d'aller chercher des champs dans une base de données puis de les transformer en xml, tout ça en php, pour les afficher dans une datagrid en Flex mais rien ne s'affiche je ne comprends pas pourtant ma requète SQL est bonne et mon xml me semble bien créé.
Flex
PHP
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:HTTPService id = "httpResult" contentType = "application/x-www-form-urlencoded" url = "" useProxy = "false" method = "POST" /> <mx:Button label="OK" click="remplir()" /> <mx:DataGrid id="datagrid"></mx:DataGrid> <mx:Script> <![CDATA[ import mx.rpc.events.ResultEvent; import mx.rpc.http.HTTPService; import mx.controls.Alert; private function remplir():void { httpResult.url = "http://localhost/bddToXML.php" ; httpResult.addEventListener("result", remplirTableau) ; httpResult.send() ; } private function remplirTableau(event:ResultEvent):void { Alert.show('connexion') ; datagrid.dataProvider = httpResult.lastResult.presidents.president ; } ]]> </mx:Script> </mx:Application>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 <?php $db = mysql_connect('localhost', 'root','') or die("erreur de connexion"); mysql_select_db('testoffice2', $db) or die("erreur de table"); $sql = "select firstname, lastname from tm_presidents" ; $req = mysql_query($sql) or die ('Erreur SQL !<br>'.$sql.'<br>'.mysql_error()) ; $_xml ="<?xml version=\"1.0\" encoding=\"utf-8\" ?>"; $_xml ="<presidents>"; while ($donnees = mysql_fetch_array($req)) { $_xml .="<president>"; $_xml .="<prenom>" . $donnees['firstname'] . "</prenom>"; $_xml .="<nom>" . $donnees['lastname'] . "</nom>"; $_xml .="</president>"; } $_xml .="</presidents>"; echo $_xml; ?>
Partager