Page 1 sur 1

boucle for pour contenu html

Posté : 12 juin 2014, 09:54
par anaval
Bonjour tout le monde !!

Je galère un peu avec ma boucle for, voilà déjà mon code qui comprends des erreurs de syntaxe...
for ($var = 1; $var <= 10; $var++)
    
    {
    
       echo '<ul>'
        <li class="itmList">
           <a href="" attr-id="HPAMID065FS0005U">
                <div class="placeholder">
            
                <img src="<?php echo $photo1; ?>" alt="nom de lo'objet : libelé">
                </div>
                <h2><?php echo $nom1; ?></h2>
                <p class="description"><?php echo $description1; ?></p>
                <p class="location">Location : <?php echo $location1; ?></p>
            </a>
        </li>  
    '</ul>'
    
    }

En fait voilà ce que j'aimerai faire, car ça ne dois pas se voir sur mon code :oops:
Avec mes variables, $nom1 , $description1, $location1 je récupère un contenu xml et je l'affiche . Le problème , c'est que parfois, il arrive que sur la même page XML, j'ai plusieur nom , descriptions , et locations à récupérer. Or, sans la boucle, il ne m'en affiche q'une, donc je voudrai que tant qu'il y des noms , descriptions, et locations, qu'il me l'affiche sous forme de liste :
Comme ceci :

Nom1
Description1
location1

Nom2
Description2
location2

Nom3
Description3
location3
etc
Une idée ? Merci :D

Re: boucle for pour contenu html

Posté : 12 juin 2014, 16:01
par telnes
hello

poste ton code sans for et le xml.


merci
++

Re: boucle for pour contenu html

Posté : 12 juin 2014, 16:22
par anaval
Salut :)

Voici le xml : très long désolé
<?xml version="1.0" encoding="utf-8"?>
<feed xml:base="http://wcf.tourinsoft.com/Syndication/cdt65/b1155573-8443-49fb-a3d0-bb05526278e6/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <id>http://wcf.tourinsoft.com/Syndication/cdt65/b1155573-8443-49fb-a3d0-bb05526278e6/Objects</id>
  <title type="text">Objects</title>
  <updated>2014-06-12T14:18:43Z</updated>
  <link rel="self" title="Objects" href="Objects" />
  <entry>
    <id>http://wcf.tourinsoft.com/Syndication/cdt65/b1155573-8443-49fb-a3d0-bb05526278e6/Objects('HPAMID065FS0003G')</id>
    <category term="TourInSoft.V5.Syndication.Syndication_PROJETPERCETIRHPANEW_1de49e6d23be47bb9d5e33ac3ea5d247.SyndicObject" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <link rel="edit" title="SyndicObject" href="Objects('HPAMID065FS0003G')" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Searchs" type="application/atom+xml;type=feed" title="Searchs" href="Objects('HPAMID065FS0003G')/Searchs" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Structure" type="application/atom+xml;type=entry" title="Structure" href="Objects('HPAMID065FS0003G')/Structure" />
    <title type="text">CAMPING LA PLENITUDE</title>
    <published>2009-08-18T11:33:36+02:00</published>
    <updated>2014-03-06T14:53:56+01:00</updated>
    <author>
      <name />
    </author>
    <content type="application/xml">
      <m:properties>
        <d:SyndicObjectID>HPAMID065FS0003G</d:SyndicObjectID>
        <d:Published m:type="Edm.DateTime">2009-08-18T11:33:36.26</d:Published>
        <d:Updated m:type="Edm.DateTime">2014-03-06T14:53:56</d:Updated>
        <d:SyndicObjectName>CAMPING LA PLENITUDE</d:SyndicObjectName>
        <d:SyndicStructureId m:type="Edm.Guid">fd82d5b3-8789-41d0-973b-409c6ff40d15</d:SyndicStructureId>
        <d:GmapLatitude>43.1186788</d:GmapLatitude>
        <d:GmapLongitude>0.31155830</d:GmapLongitude>
        <d:ObjectTypeFix>80AADCB5-86D1-408C-912D-52486BA9593C</d:ObjectTypeFix>
        <d:ObjectTypeName>Hôtellerie de plein air (camping)</d:ObjectTypeName>
        <d:SyndicObjectOrder m:type="Edm.Int64">3</d:SyndicObjectOrder>
        <d:ListingNOMOFFRE>CAMPING LA PLENITUDE</d:ListingNOMOFFRE>
        <d:ListingSUPERFICIE>1m2</d:ListingSUPERFICIE>
        <d:ListingLABELHANDI m:null="true" />
        <d:ListingMARQUES m:null="true" />
        <d:ListingPHOTOS>Libellé : Chalet Plénitude|URL : <img src="http://cdt65.media.tourinsoft.eu/upload/Chalet-Ple-nitude.jpg">#Libellé : Emplacements Plénitude|URL : <img src="http://cdt65.media.tourinsoft.eu/upload/Emplacements-Ple-nitude.jpg">#Libellé : HPMH07 - La Plénitude - Exterieur|URL : <img src="http://cdt65.media.tourinsoft.eu/upload/HPMH07---La-Plenitude---Exterieur.jpg">#Libellé : HPMH07 - La Plénitude - Aire de jeux|URL : <img src="http://cdt65.media.tourinsoft.eu/upload/HPMH07---La-Plenitude---Aire-de-jeux.jpg"></d:ListingPHOTOS>
        <d:ListingNBEMPCLASSES>36</d:ListingNBEMPCLASSES>
        <d:ListingDESCRIPTIONPRESTATION m:null="true" />
        <d:ListingACCUEILHANDI>oui</d:ListingACCUEILHANDI>
        <d:ListingEMAIL>[email protected]</d:ListingEMAIL>
        <d:ListingACCUEILGROUPE xml:space="preserve">Accueil groupe : oui|Nombre de personnes minimum : |Nombre de personnes maximum : |Parking autocars :</d:ListingACCUEILGROUPE>
        <d:ListingTELEPHONE>05 62 39 14 56</d:ListingTELEPHONE>
        <d:ListingMODEPAIEMENT>Carte bleue;Chèques bancaires et postaux;Chèques Vacances;Espèces</d:ListingMODEPAIEMENT>
        <d:ListingACTIVITES>Animations ponctuelles;Baignade</d:ListingACTIVITES>
        <d:ListingSITEWEB>http://www.camping-capvern.com</d:ListingSITEWEB>
        <d:ListingPHOTOPRINCIPALE>Libellé : La plénitude 2014|URL : <img src="http://cdt65.media.tourinsoft.eu/upload/La-plenitude-2014.JPG">Libellé : HPMH07 - La Plénitude - Roulotte Arizona|URL : <img src="http://cdt65.media.tourinsoft.eu/upload/HPMH07---La-Plenitude---Roulotte-Arizona.jpg">Libellé : HPMH07 - La Plénitude - Roulotte Arizona|URL : <img src="http://cdt65.media.tourinsoft.eu/upload/HPMH07---La-Plenitude---Roulotte-Arizona.jpg"></d:ListingPHOTOPRINCIPALE>
        <d:ListingEQUIPEMENTS>Boulodrome;Branchements d'eau;Branchements électriques;Cabine téléphonique / Point phone;Emplacement camping car;Equipement camping car;Evacuation des eaux usées;Jeux pour enfants;Ping-pong;Piscine;Salle de réunion;Salon de télévision;Station service camping car</d:ListingEQUIPEMENTS>
        <d:ListingACTIVITESPROXIMITE>Thermes;Discothèque;Casino;Cinéma;Commerces;Centre de remise en forme;Mini-golf;Pêche;Piscine;Randonnée;Sentiers balisés;Station de ski;Tennis;Vélo</d:ListingACTIVITESPROXIMITE>
        <d:ListingRESERVATION>Structure : Réservation centrale NESTE BARONNIES|Type : Téléphone filaire|Coordonnées : 05 62 40 91 16#Structure : Réservation centrale NESTE BARONNIES|Type : Mél|Coordonnées : [email protected]#Structure : Réservation directe|Type : Mél|Coordonnées : [email protected]#Structure : Réservation directe|Type : Téléphone cellulaire|Coordonnées : 06 59 61 18 69#Structure : Réservation directe|Type : Téléphone filaire|Coordonnées : 05 62 39 14 56</d:ListingRESERVATION>
        <d:ListingOUVERTUREACCUEIL xml:space="preserve">Début de la période : 29/03/2014|Fin de la période : 15/11/2014|Horaires d'ouverture : h à h|Horaires d'ouverture : h à h|Jour(s) de fermeture :</d:ListingOUVERTUREACCUEIL>
        <d:ListingADRESSE2>1000 Route de Provence</d:ListingADRESSE2>
        <d:ListingRESERVATIONURL>Structure : Réservation directe|URL : http://www.camping-capvern.com</d:ListingRESERVATIONURL>
        <d:ListingTYPEGROUPE m:null="true" />
        <d:ListingSERVICES>Animaux acceptés;Commerce alimentaire;Dépôt de glace;Lave linge;Location bungalow / HLL;Location chalets;Location de mobil home;Point courrier;Produits locaux;Sèche linge;Surveillance de nuit;Wifi</d:ListingSERVICES>
        <d:ListingDESCRIPTIONCOMMERCIALE>A Capvern Les Bains, camping de 36 emplacements sur trois niveaux au coeur du village thermal, à 800m des Thermes.</d:ListingDESCRIPTIONCOMMERCIALE>
        <d:ListingPORTABLE>06 59 61 18 69</d:ListingPORTABLE>
        <d:ListingPROVINCE m:null="true" />
        <d:ListingCHAINES m:null="true" />
        <d:ListingACCUEILANIMAUX>oui</d:ListingACCUEILANIMAUX>
        <d:ListingINSEE>65127</d:ListingINSEE>
        <d:ListingTARIF xml:space="preserve">Libellé : Prix adulte / jour|Tarif minimal : 4,1€|Tarif maximal : 4,4€|Age maxi pour réduction : |Complément tarif : #Libellé : Prix tente / jour|Tarif minimal : 4,5€|Tarif maximal : 5,1€|Age maxi pour réduction : |Complément tarif : #Libellé : Prix camping-car / jour|Tarif minimal : 4,5€|Tarif maximal : 5,1€|Age maxi pour réduction : |Complément tarif : #Libellé : Prix caravane / jour|Tarif minimal : 4,5€|Tarif maximal : 5,1€|Age maxi pour réduction : |Complément tarif : #Libellé : Prix électricité / jour|Tarif minimal : 4,55€|Tarif maximal : €|Age maxi pour réduction : |Complément tarif :</d:ListingTARIF>
        <d:ListingNATURISME>non</d:ListingNATURISME>
        <d:ListingLATITUDE>43.1186788</d:ListingLATITUDE>
        <d:ListingADRESSE1></d:ListingADRESSE1>
        <d:ListingCATEGORIE>3 étoiles</d:ListingCATEGORIE>
        <d:ListingLANGUE>Anglais;Espagnol</d:ListingLANGUE>
        <d:ListingCAPACITE>Capacité globale : 140 personnes</d:ListingCAPACITE>
        <d:ListingADRESSE3></d:ListingADRESSE3>
        <d:ListingCOMMUNE>CAPVERN</d:ListingCOMMUNE>
        <d:ListingTYPESTRUCTURE>Terrain de camping classé - tourisme</d:ListingTYPESTRUCTURE>
        <d:ListingRESAENLIGNE>non</d:ListingRESAENLIGNE>
        <d:ListingCARAVANEIGE>non</d:ListingCARAVANEIGE>
        <d:ListingCODEPOSTAL>65130</d:ListingCODEPOSTAL>
        <d:ListingVIDEOS m:null="true" />
        <d:ListingFAX m:null="true" />
        <d:ListingOMBRAGE>oui</d:ListingOMBRAGE>
        <d:ListingLONGITUDE>0.31155830</d:ListingLONGITUDE>
        <d:ListingPHOTOPRINCIPALE_DIAPO>La-plenitude-2014.JPG||La plénitude 2014||##HPMH07---La-Plenitude---Roulotte-Arizona.jpg||HPMH07 - La Plénitude - Roulotte Arizona||##HPMH07---La-Plenitude---Roulotte-Arizona.jpg||HPMH07 - La Plénitude - Roulotte Arizona||</d:ListingPHOTOPRINCIPALE_DIAPO>
      </m:properties>
    </content>
    <geo:lat xmlns:geo="http://www.georss.org/georss">43.1186788</geo:lat>
    <geo:long xmlns:geo="http://www.georss.org/georss">0.31155830</geo:long>
  </entry>
  <entry>
    <id>http://wcf.tourinsoft.com/Syndication/cdt65/b1155573-8443-49fb-a3d0-bb05526278e6/Objects('HPAMID065FS0005U')</id>
    <category term="TourInSoft.V5.Syndication.Syndication_PROJETPERCETIRHPANEW_1de49e6d23be47bb9d5e33ac3ea5d247.SyndicObject" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <link rel="edit" title="SyndicObject" href="Objects('HPAMID065FS0005U')" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Searchs" type="application/atom+xml;type=feed" title="Searchs" href="Objects('HPAMID065FS0005U')/Searchs" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Structure" type="application/atom+xml;type=entry" title="Structure" href="Objects('HPAMID065FS0005U')/Structure" />
    <title type="text">CAMPING LES CRAOUES</title>
    <published>2009-08-18T11:48:26+02:00</published>
    <updated>2014-02-28T16:15:52+01:00</updated>
    <author>
      <name />
    </author>
    <content type="application/xml">
      <m:properties>
        <d:SyndicObjectID>HPAMID065FS0005U</d:SyndicObjectID>
        <d:Published m:type="Edm.DateTime">2009-08-18T11:48:26.823</d:Published>
        <d:Updated m:type="Edm.DateTime">2014-02-28T16:15:52.373</d:Updated>
        <d:SyndicObjectName>CAMPING LES CRAOUES</d:SyndicObjectName>
        <d:SyndicStructureId m:type="Edm.Guid">fd82d5b3-8789-41d0-973b-409c6ff40d15</d:SyndicStructureId>
        <d:GmapLatitude>43.1053480</d:GmapLatitude>
        <d:GmapLongitude>0.3234634</d:GmapLongitude>
        <d:ObjectTypeFix>80AADCB5-86D1-408C-912D-52486BA9593C</d:ObjectTypeFix>
        <d:ObjectTypeName>Hôtellerie de plein air (camping)</d:ObjectTypeName>
        <d:SyndicObjectOrder m:type="Edm.Int64">5</d:SyndicObjectOrder>
        <d:ListingNOMOFFRE>CAMPING LES CRAOUES</d:ListingNOMOFFRE>
        <d:ListingSUPERFICIE>1,5m2</d:ListingSUPERFICIE>
        <d:ListingLABELHANDI m:null="true" />
        <d:ListingMARQUES m:null="true" />
        <d:ListingPHOTOS m:null="true" />
        <d:ListingNBEMPCLASSES>80</d:ListingNBEMPCLASSES>
        <d:ListingDESCRIPTIONPRESTATION m:null="true" />
        <d:ListingACCUEILHANDI>oui</d:ListingACCUEILHANDI>
        <d:ListingEMAIL>[email protected]</d:ListingEMAIL>
        <d:ListingACCUEILGROUPE m:null="true" />
        <d:ListingTELEPHONE>05 62 39 02 54</d:ListingTELEPHONE>
        <d:ListingMODEPAIEMENT>Cartes de paiement;Chèques bancaires et postaux;Chèques Vacances;Espèces</d:ListingMODEPAIEMENT>
        <d:ListingACTIVITES>Animation;Baignade;Randonnée pédestre;Vélo / VTT</d:ListingACTIVITES>
        <d:ListingSITEWEB>http://www.camping-les-craoues.net</d:ListingSITEWEB>
        <d:ListingPHOTOPRINCIPALE>Libellé : Les Craoues|URL : <img src="http://cdt65.media.tourinsoft.eu/upload/Les-Craoues.jpg">Libellé : craoues chalet|URL : <img src="http://cdt65.media.tourinsoft.eu/upload/craoues-chalet.jpg">Libellé : craoues allee|URL : <img src="http://cdt65.media.tourinsoft.eu/upload/craoues-allee.jpg"></d:ListingPHOTOPRINCIPALE>
        <d:ListingEQUIPEMENTS>Boulodrome;Branchements électriques;Emplacement camping car;Evacuation des eaux usées;Jeux pour enfants;Ping-pong;Piscine;Salle de jeux;Salle de réunion</d:ListingEQUIPEMENTS>
        <d:ListingACTIVITESPROXIMITE>Piscine;Tennis;Pêche;Sentiers balisés;Canoe-kayak;Thermes;Centre de remise en forme;Plan d'eau;Discothèque;Casino;Cinéma;Commerces;Rivière</d:ListingACTIVITESPROXIMITE>
        <d:ListingRESERVATION>Structure : Réservation directe|Type : Téléphone filaire|Coordonnées : 05 62 39 02 54#Structure : Réservation directe|Type : Mél|Coordonnées : [email protected]#Structure : Réservation directe|Type : Téléphone cellulaire|Coordonnées : 06 31 37 78 58</d:ListingRESERVATION>
        <d:ListingOUVERTUREACCUEIL xml:space="preserve">Début de la période : 01/01/2013|Fin de la période : 31/12/2013|Horaires d'ouverture : h à h|Horaires d'ouverture : h à h|Jour(s) de fermeture :</d:ListingOUVERTUREACCUEIL>
        <d:ListingADRESSE2>682 Rue du 8 Mai 1945</d:ListingADRESSE2>
        <d:ListingRESERVATIONURL>Structure : Réservation directe|URL : http://www.camping-les-craoues.net</d:ListingRESERVATIONURL>
        <d:ListingTYPEGROUPE m:null="true" />
        <d:ListingSERVICES>Accès handicapés;Animaux acceptés;Garage mort;Lave linge;Location bungalow / HLL;Location bungatoile;Location chalets;Location de mobil home;Sèche linge;Terrain fermé la nuit;Wifi</d:ListingSERVICES>
        <d:ListingDESCRIPTIONCOMMERCIALE>A Capvern Village, camping de 80 emplacements, à l'entrée du village, à 3km des Thermes.</d:ListingDESCRIPTIONCOMMERCIALE>
        <d:ListingPORTABLE>06 31 37 78 58</d:ListingPORTABLE>
        <d:ListingPROVINCE m:null="true" />
        <d:ListingCHAINES m:null="true" />
        <d:ListingACCUEILANIMAUX>oui</d:ListingACCUEILANIMAUX>
        <d:ListingINSEE>65127</d:ListingINSEE>
        <d:ListingTARIF xml:space="preserve">Libellé : Prix adulte / jour|Tarif minimal : 4€|Tarif maximal : 4,5€|Age maxi pour réduction : |Complément tarif : Hors Taxe de Séjour et prix emplacement selon la saison.#Libellé : Prix tente / jour|Tarif minimal : 4,25€|Tarif maximal : 5€|Age maxi pour réduction : |Complément tarif : #Libellé : Prix camping-car / jour|Tarif minimal : 4,25€|Tarif maximal : 5€|Age maxi pour réduction : |Complément tarif : #Libellé : Prix caravane / jour|Tarif minimal : 4,25€|Tarif maximal : 5€|Age maxi pour réduction : |Complément tarif : #Libellé : Prix électricité / jour|Tarif minimal : 3€|Tarif maximal : 5,25€|Age maxi pour réduction : |Complément tarif : #Libellé : Location chalet / semaine|Tarif minimal : €|Tarif maximal : €|Age maxi pour réduction : |Complément tarif : #Libellé : Location mobil home / semaine|Tarif minimal : €|Tarif maximal : €|Age maxi pour réduction : |Complément tarif : #Libellé : Location bungatoile / semaine|Tarif minimal : €|Tarif maximal : €|Age maxi pour réduction : |Complément tarif :</d:ListingTARIF>
        <d:ListingNATURISME>non</d:ListingNATURISME>
        <d:ListingLATITUDE>43.1053480</d:ListingLATITUDE>
        <d:ListingADRESSE1></d:ListingADRESSE1>
        <d:ListingCATEGORIE>3 étoiles</d:ListingCATEGORIE>
        <d:ListingLANGUE>Anglais</d:ListingLANGUE>
        <d:ListingCAPACITE m:null="true" />
        <d:ListingADRESSE3></d:ListingADRESSE3>
        <d:ListingCOMMUNE>CAPVERN</d:ListingCOMMUNE>
        <d:ListingTYPESTRUCTURE>Terrain de camping classé - tourisme</d:ListingTYPESTRUCTURE>
        <d:ListingRESAENLIGNE>non</d:ListingRESAENLIGNE>
        <d:ListingCARAVANEIGE>oui</d:ListingCARAVANEIGE>
        <d:ListingCODEPOSTAL>65130</d:ListingCODEPOSTAL>
        <d:ListingVIDEOS m:null="true" />
        <d:ListingFAX m:null="true" />
        <d:ListingOMBRAGE>oui</d:ListingOMBRAGE>
        <d:ListingLONGITUDE>0.3234634</d:ListingLONGITUDE>
        <d:ListingPHOTOPRINCIPALE_DIAPO>Les-Craoues.jpg||Les Craoues||##craoues-chalet.jpg||craoues chalet||##craoues-allee.jpg||craoues allee||</d:ListingPHOTOPRINCIPALE_DIAPO>
      </m:properties>
    </content>
    <geo:lat xmlns:geo="http://www.georss.org/georss">43.1053480</geo:lat>
    <geo:long xmlns:geo="http://www.georss.org/georss">0.3234634</geo:long>
  </entry>
</feed>


Comme tu peux voir il y a deux entrés dans ce fichier xml, et j'arrive à afficher que la deuxième...
voici mon code php
<?php
$fichier = 'http://wcf.tourinsoft.com/Syndication/cdt65/b1155573-8443-49fb-a3d0-bb05526278e6/Objects?$filter=ListingCOMMUNE eq\'CAPVERN\'';

$dom = new DOMDocument('utf-8');
if (!$dom->load($fichier))
{
    die('Impossible de charger le fichier XML');
}
 
$itemList = $dom->getElementsByTagName('properties');

foreach ($itemList as $item2)
{
    $nom = $item2->getElementsByTagName('ListingCOMMUNE');
    $nom1 = $nom->item(0)->nodeValue; 
    
    $photo = $item2->getElementsByTagName('ListingPHOTOPRINCIPALE');
    $photo1 = $photo->item(0)->nodeValue;   
    $photo1 = str_replace('URL : ', '', $photo1);
    $photo1 = str_replace('Libellé :', '', $photo1); echo '</p>';
    
    
     $description = $item2->getElementsByTagName('ListingDESCRIPTIONCOMMERCIALE');
    $description1 = $description->item(0)->nodeValue;  
    
    $location = $item2->getElementsByTagName('ListingRESERVATION');
    $location1 = $location->item(0)->nodeValue; 
}


et le code html qui va avec :
<ul>
            <li class="itmList">
                <a href="capvern.php" attr-id="HPAMID065FS0005U">
                <div class="placeholder">
            
                   <?php echo $photo1; ?>" alt="nom de lo'objet : libelé">
                    
                </div>
                
                <h2><?php echo $nom1; ?></h2>
                
                <p class="description"><?php echo $description1; ?></p>
                <p class="location">Location : <?php echo $location1; ?></p>
            </a>
            </li>
        
        
    </ul>
Voilà :)

Re: boucle for pour contenu html

Posté : 12 juin 2014, 16:45
par telnes
hello

dans ta boucle tu écrase à chaque fois

utilise des tableaux $nom1[] ou element[]['nom] ... pour ensuite les parcourir (foreach encore)