Bonjours a tous.
J'utilise le Php pour créer un fichier XML contenant des données d'une base de données.
Jusque ici tout va bien mon souci c'est que pour 30entrée ça marche bien c'est assez rapide mais dans des cas ou j'ai 300 voir 3000 entrées la génération du Xml peut prendre plusieurs 10ene de minutes.
Pourriez vous me conseiller pour optimiser mon code afin de diminuer la durée de création de mon Xml? (j'espers ne pas flooder :s)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
 
$cnx = mysql_connect( "****", "*****", "******" );
$db= mysql_select_db( "******" );
$sql = "SELECT * FROM bien WHERE annonceur_bien='43'";
$sqlcount = "SELECT * FROM bien WHERE annonceur_bien='43' AND description_bien != '' ";
$sql2 = "SELECT * FROM bien, annonceur WHERE no_annonceur ='43' AND annonceur_bien ='43' AND no_annonceur = annonceur_bien";
$numero_page =4;
$requete = mysql_query( $sql, $cnx );
$requetecount = mysql_query( $sqlcount, $cnx );
$requete2 = mysql_query($sql2, $cnx);
$row2 = mysql_fetch_array($requete2);
$row = mysql_fetch_array($requete);
$nb_bien = mysql_num_rows($requetecount);
$nb_bien -=1;
 
// COUVERTURE
 $xml = '<?xml version="1.0" encoding="utf-8"?>';
 $xml .= '<content width="300" height="400" hcover="false" transparency="false">';
 
 if($row['tel_annonceur_bien'] == "" OR $row['tel_annonceur_bien'] == "0")
 {$tel = "";}
 else
 {$tel = "Tel : ".$row['tel_annonceur_bien']."";
 } 
 if($row['gsm_annonceur_bien'] == "" OR $row['gsm_annonceur_bien'] == "0")
 {$gsm = "";}
 else
 {$gsm = "Gsm : ".$row['gsm_annonceur_bien']."";} 
 
 if($row['fax_annonceur_bien'] == "" OR $row['fax_annonceur_bien'] == "0")
 {$fax = "";}
 else
 {$fax = "Fax : ".$row['fax_annonceur_bien']."";} 
 
 if($row['mail_annonceur_bien']=="" OR $row['mail_annonceur_bien']=="0")
 {$mail = "";}
 else
 {$mail = " Mail : ".$row['mail_annonceur_bien']."";}
 
 $xml .='<page agence="'.$row['nom_annonceur_bien'].'" bg="couv.jpg" contact1="'.$row['nom_annonceur_bien'].'" contact2= "'.$tel.' '.$gsm.'" contact3="'.  $fax.' '.$mail.'" logo="http://********.fr/'.$row2['chemin_logo_annonceur'].'" preLoad="false">';
 $xml .='</page>';
  $xml .='<page nb_bien="'.$nb_bien.'" bg="1.jpg" preLoad="false">';
 $xml .='</page>';
 $xml .='<page nb_bien="'.$nb_bien.'" lapage= "sommaire" bg="2.jpg" preLoad="false">';
 $xml .='</page>';
 while ($row = mysql_fetch_array($requete)) {
 //REQUETE PHOTO 
 $sql6 = 'SELECT chemin_photo FROM bien, photo WHERE no_bien ='.$row['no_bien'].' AND bien_photo ='.$row['no_bien'].' AND no_bien = bien_photo';
  //$sql6 = 'SELECT chemin_photo FROM bien, photo WHERE no_bien =43279  AND bien_photo =43279 AND no_bien = bien_photo';
 $requete6 = mysql_query($sql6, $cnx);
$i=0;
while ($row6 = mysql_fetch_array($requete6))
 {
$tableau[$i] = $row6['chemin_photo'];
$i++;
}
 //REQUETE NOM VILLE
 $sql4 = 'SELECT * FROM bien, ville WHERE ville_bien='.$row['ville_bien'].' AND no_ville='.$row['ville_bien'].' AND ville_bien=no_ville';
 $requete4 = mysql_query($sql4, $cnx);
 $row4 = mysql_fetch_array($requete4);
 //REQUETE NOM DEPARTEMENT
 $sql5 = 'SELECT * FROM bien, departement WHERE departement_bien='.$row['departement_bien'].' AND no_departement='.$row['departement_bien'].' AND departement_bien=no_departement';
 $requete5 = mysql_query($sql5, $cnx);
 $row5 = mysql_fetch_array($requete5);
 
 if ($row['type_bien'] == 1)
 {
 $type_bien = "Appartement";
 }
 else if ($row['type_bien'] == 2)
 {
  $type_bien = "Bungalow";
 }
 else if($row['type_bien'] == 3)
 {
  $type_bien = "Chalet";
 }
 else if($row['type_bien'] == 4)
 {
  $type_bien = "Chambre";
 }
 else if($row['type_bien'] == 5)
 {
  $type_bien = "Château";
 }
 else if($row['type_bien'] == 6)
 {
  $type_bien = "Duplex";
 }
 else if($row['type_bien'] == 7)
 {
  $type_bien = "Ferme";
 }
 else if($row['type_bien'] == 8)
 {
  $type_bien = "Fermette";
 }
 else if($row['type_bien'] == 9)
 {
  $type_bien = "Garage - Parking";
 }
 else if($row['type_bien'] == 10)
 {
  $type_bien = "Gros oeuvre";
 }
 else if($row['type_bien'] == 11)
 {
  $type_bien = "Jardin - Etang - Forêt";
 }
 else if($row['type_bien'] == 13)
 {
   $type_bien = "Loft";
 }
 else if($row['type_bien'] == 14)
 {
   $type_bien = "Lotissement";
 }
 else if($row['type_bien'] == 15)
 {
   $type_bien = "Maison individuelle";
 }
 else if($row['type_bien'] == 16)
 {
   $type_bien = "Maison - Immeuble de rapport";
 }
 else if($row['type_bien'] == 17)
 {
   $type_bien = "Maison de maître";
 }
 else if($row['type_bien'] == 18)
 {
   $type_bien = "Maison jumelée";
 }
 else if($row['type_bien'] == 19)
 {
   $type_bien = "Maison mitoyenne";
 }
 else if($row['type_bien'] == 20)
 {
   $type_bien = "Maison";
 }
 else if($row['type_bien'] == 21)
 {
   $type_bien = "Studio";
 }
 else if($row['type_bien'] == 22)
 {
   $type_bien = "Terrain";
 }
 else if($row['type_bien'] == 25)
 {
   $type_bien = "Entrepôt";
 }
 else if($row['type_bien'] == 26)
 {
   $type_bien = "Bureau";
 }
  else if($row['type_bien'] == 27)
 {
   $type_bien = "Restauration / Hotellerie";
 }
 else if($row['type_bien'] == 28)
 {
   $type_bien = "Fonds de Commerce";
 } else if($row['type_bien'] == 29)
 {
   $type_bien = "Terrain industriel";
 }
 else if($row['type_bien'] == 30)
 {
   $type_bien = "Résidence";
 } else if($row['type_bien'] == 31)
 {
   $type_bien = "Maison clé en main";
 }
 else if($row['type_bien'] == 32)
 {
   $type_bien = "Immeuble résidentiel";
 } else if($row['type_bien'] == 33)
 {
   $type_bien = "Local de commerce";
 }
 
 else if($row['type_bien'] == 34)
 {
   $type_bien = "Villa";
 }
 
 else if($row['type_bien'] == 35)
 {
   $type_bien = "Immeuble";
 }
 
 else if($row['type_bien'] == 36)
 {
   $type_bien = "Autres";
 }
 else
 {
 $type_bien = "";
 }
 //CONTROLE PHOTO
 if ($row3['chemin_photo'] == "")
 { 
 $photo = ""; } 
 else 
 {
 $photo = 'http://********.fr/'.$row3['chemin_photo'].'';
 }
 //CONTROLE SURFACE
 if($row['surface_bien'] == "0")
 { $surface= "";}
 else
 {$surface= $row['surface_bien'];}
 //CONTROLE VILLE BIEN
 if ($row4['nom_ville'] == "")
 {
 $nom_ville_bien = "Non renseigné";
 }
 else
 {
 $nom_ville_bien = utf8_encode($row4['nom_ville']);
 }
 //CONTROLE DEPARTEMENT
 if ($row5['nom_departement'] == "")
 {
 $nom_departement_bien = "Non renseigné";
 }
 else
 {
 $nom_departement_bien = $row5['nom_departement'];
 }
 // CHANTROLE CHAMBRE
 if ($row['nb_chambre_bien'] == "0")
 {
 $chambre = "Non renseigné";
 }
else
{
$chambre = $row['nb_chambre_bien'];
}
 //SI PAS DE DESCRIPTION -> PAS DE PAGE
  if ($row['description_bien'] != "" )
 {
 $description = utf8_encode(html_entity_decode($row['description_bien']));
 // PAGES PHOTO
 $xml .= '<page bg="1.jpg" nb_bien="'.$nb_bien.'" preLoad="false" photo_bien1="http:/****.fr/'.$tableau[0].'" photo_bien2="http://***.fr/'.$tableau[1].'" photo_bien3="http://****.fr/'.$tableau[2].'" photo_bien4="http://***.fr/'.$tableau[3].'" photo_bien5="http://***.fr/'.$tableau[4].'" photo_bien6="http://****.fr/'.$tableau[5].'" >'; 
 $xml .= '</page>';
 $numero_page++;
//PAGE DESCRIPTION
 $xml .= '<page desc="'.$description.'" bg="2.jpg" nb_bien="'.$nb_bien.'" telephone ="'.$row['tel_annonceur_bien'].'" page = "'.$numero_page.'" reference="'.$row['no_bien'].'" chambre="'.$chambre.'" departement="'.$nom_departement_bien.'" type_bien = "Type : '.$type_bien.' " surface="'.$surface.'" ville_bien = "'.$nom_ville_bien.'" photo_bien ="" btn_haut="btn_up" btn_bas="btn_down" agence ="" preLoad="false" prix="Prix : '.$row['prix_bien'].' €" contact1="" contact2= "" contact3="" logo="" >'; 
 $xml .= '</page>';
 $numero_page++;
}
 
 }
 
 $xml .='<page nb_bien="'.$nb_bien.'" bg="der.jpg" preLoad="false">';
 $xml .='</page>';
 $xml .= '</content>';
 $fp = fopen("pages.xml", 'w+');
 fputs($fp, $xml);
 fclose($fp);
?>
Merci d'avance
Benoit