Boucle for

bonsoir,


for($i = 1; $i >= 8; $i--){

echo'<figure style="display:inline-block;border:none;padding:1px;">';
echo '<img width="390" height="580" style="margin:55px 0 60px 250px;" src="' . $img3_1 .'" alt="">';
echo '<img width="960" height="800" style="margin:55px 0 0 -280px;" src="' . $img_1 .'" alt="">';
echo '<img width="390" height="580" style="margin:55px 0 60px 260px;" src="' . $img3_4 .'" alt="">';
echo '<img width="960" height="800"style="margin:55px 0 -50px -280px;" src="' . $img_4 .'" alt="">';
echo '<img width="940" height="800"style="margin:25px 0 50px 250px;" src="' . $img3_2 .'" alt="">';
echo '<img width="380" height="600" style="margin:25px 0 90px 240px;" src="' . $img1_2 .'" alt="">';
echo '<img width="940" height="800" style="margin:25px 0 50px 200px;" src="' . $img3_3 .'" alt="">';
echo '<img width="380" height="600" style="margin:25px 0 90px 40px;" src="' . $img1_3 .'" alt="">';
echo'</figure>';

break;
}


avant la boucle FOR mon image se multiplie par 8 et maintenant avec la boucle j'en ais plus du tout, pouvez vous m'expliquez svp

6 réponses


  1. <?php

    error_reporting(E_ALL);
    ini_set('display_errors', TRUE);
    ini_set('display_startup_errors', TRUE);

    require_once "../inc/inc_catalogue.php";

    require_once "../inc/inc_secondcatalogue.php";

    $id = !empty($_GET['id']) ? $_GET['id'] : NULL;

    if($id){

    $audio3 = !empty($catalogue[$id]['audio3']) ? $catalogue[$id]['audio3'] : NULL;
    $img_1 = !empty($catalogue[$id]['img_1']) ? $catalogue[$id]['img_1'] : NULL;
    $img2 = !empty($catalogue[$id]['img2']) ? $catalogue[$id]['img2'] : NULL;
    $img3_1 = !empty($catalogue[$id]['img3_1']) ? $catalogue[$id]['img3_1'] : NULL;
    $text = !empty($catalogue[$id]['text']) ? $catalogue[$id]['text'] : NULL;
    $color = !empty($catalogue[$id]['color']) ? $catalogue[$id]['color'] : NULL;

    $audio4 = !empty($catalogue_1[$id]['audio4']) ? $catalogue_1[$id]['audio4'] : NULL;
    $img_4 = !empty($catalogue_1[$id]['img_4']) ? $catalogue_1[$id]['img_4'] : NULL;
    $img2 = !empty($catalogue_1[$id]['img2']) ? $catalogue_1[$id]['img2'] : NULL;
    $img3_4 = !empty($catalogue_1[$id]['img3_4']) ? $catalogue_1[$id]['img3_4'] : NULL;
    $text = !empty($catalogue_[$id]['text']) ? $catalogue_[$id]['text'] : NULL;
    $color = !empty($catalogue_1[$id]['color']) ? $catalogue_1[$id]['color'] : NULL;

    $audio1 = !empty($secondcatalogue[$id]['audio1']) ? $secondcatalogue[$id]['audio1'] : NULL;
    $img1_2 = !empty($secondcatalogue[$id]['img1_2']) ? $secondcatalogue[$id]['img1_2'] : NULL;
    $img2 = !empty($secondcatalogue[$id]['img2']) ? $secondcatalogue[$id]['img2'] : NULL;
    $img3_2 = !empty($secondcatalogue[$id]['img3_2']) ? $secondcatalogue[$id]['img3_2'] : NULL;
    $text = !empty($secondcatalogue[$id]['text']) ? $secondcatalogue[$id]['text'] : NULL;
    $color = !empty($secondcatalogue[$id]['color']) ? $secondcatalogue[$id]['color'] : NULL;

    $audio2 = !empty($secondcatalogue_1[$id]['audio2']) ? $secondcatalogue_1[$id]['audio2'] : NULL;
    $img1_3 = !empty($secondcatalogue_1[$id]['img1_3']) ? $secondcatalogue_1[$id]['img1_3'] : NULL;
    $img2 = !empty($secondcatalogue_1[$id]['img2']) ? $secondcatalogue_1[$id]['img2'] : NULL;
    $img3_3 = !empty($secondcatalogue_1[$id]['img3_3']) ? $secondcatalogue_1[$id]['img3_3'] : NULL;
    $text = !empty($secondcatalogue_[$id]['text']) ? $secondcatalogue_[$id]['text'] : NULL;
    $color = !empty($secondcatalogue_1[$id]['color']) ? $secondcatalogue_1[$id]['color'] : NULL;

    echo'<figure style="display:inline-block;border:none;padding:1px;">';
    for($i = 8; $i >= 1; $i--){
    echo '<img width="390" height="580" style="margin:55px 0 60px 250px;" src="' . $img3_1 .'" alt="">';
    echo '<img width="960" height="800" style="margin:55px 0 0 -280px;" src="' . $img_1 .'" alt="">';
    echo '<img width="390" height="580" style="margin:55px 0 60px 260px;" src="' . $img3_4 .'" alt="">';
    echo '<img width="960" height="800"style="margin:55px 0 -50px -280px;" src="' . $img_4 .'" alt="">';
    echo '<img width="940" height="800"style="margin:25px 0 50px 250px;" src="' . $img3_2 .'" alt="">';
    echo '<img width="380" height="600" style="margin:25px 0 90px 240px;" src="' . $img1_2 .'" alt="">';
    echo '<img width="940" height="800" style="margin:25px 0 50px 200px;" src="' . $img3_3 .'" alt="">';
    echo '<img width="380" height="600" style="margin:25px 0 90px 40px;" src="' . $img1_3 .'" alt="">';

    }
    echo'</figure>';

    echo'<audio style="display:inline-block;margin-left:0;margin-bottom:80px;margin-top:-50px;" controls preload="auto">';
    echo'<source src="'. $audio1 .'" type="audio/mp3"/>';
    echo'<source src="'. $audio2 .'" type="audio/mp3"/>';
    echo'<source src="'. $audio3 .'" type="audio/mp3"/>';
    echo'<source src="'. $audio4 .'" type="audio/mp3"/>';
    echo'</audio>';

    echo'<div style="float:left;margin-left:850px; margin-top:40px; margin-bottom:10px;">';
    echo'<a href="'. $audio1 .'" download><img style="width="76"; height="76" src="../img/bouton-telecharger.png"></a>';
    echo'<a href="'. $audio2 .'" download><img style="width="76"; height="76" src="../img/bouton-telecharger.png"></a>';
    echo'<a href="'. $audio3 .'" download><img style="width="76"; height="76" src="../img/bouton-telecharger.png"></a>';
    echo'<a href="'. $audio4 .'" download><img style="width="76"; height="76" src="../img/bouton-telecharger.png"></a>';
    echo'</div>';

    echo'<div style="float:left;width:150px; height:80px; margin:-65px 0 0 710px;">';
    echo'<a style="padding:1em 1.5em .7em 1.5em;border:1px solid #000;text-decoration:none;background:#fff;font-family:notoserif;font-weight:bold;color:#000;" href="http://s642262600.onlinehome.fr//index.php?img=..%2Fimg%2Flivre_1.jpg&prix=18.90&livre_1=ACHETER" >ACHETER</a>';
    echo'</div>';

    }else{
    echo "Catalogue inconnu !";
    }

    ?>
    </section>

    <?php
    require('../inc/inc_footer.php');
    ?>
    1. @yg_be
      <!doctype html>
      <html lang="fr">
      <head>
      <title>françaispouradulte
      </title>
      <!------------------------------balises-meta--------------------------------->
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta name="description" content="Bandes sons Au boulot ! livre 1 et livre 2 – le français pour adultes – Valérie <b>VERMURIE</b>">
      <!-----------------------------styles-css------------------------------------>
      <link rel="stylesheet" href="../css/style.css" media="all">
      <link rel="stylesheet" href="../css/style_exo_1.css" media="all">
      <link rel="stylesheet" href="../css/contact.css" media="all">
      <link rel="stylesheet" href="../css/normalize.css" media="all">
      <link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" />
      <link rel="stylesheet" type="text/css" href="../css/animate.css" />
      <link rel="icon" type="image/png" href="../favicon.png" />
      <link rel="apple-touch-icon" sizes="120x120" href="../apple-touch-icon-120x120-precomposed.png" /> <link rel="apple-touch-icon" sizes="152x152" href="../apple-touch-icon-152x152-precomposed.png" />
      <!-----------------------------styles-font----------------------------------->
      <link href='https://fonts.googleapis.com/css?family=Kreon:400,700,300' rel='stylesheet' type='text/css'>
      <!-----------------------------script_js----------------------------------->
      <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
      </script>
      <script src="jquery.js"></script>
      <script src="audioplayer.js"></script>
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
      <script src="audiojs/audio.min.js"></script>
      <!--[if IE9]>
      <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
      <![endif]-->
      <style>

      img{

      float:left;

      }

      </style>
      </head>
      <body>
      <div id="wrapper">
      <header class="header_color">
      <div id="header_logo">
      <img src="../img/logo.png" alt="logo_francais_pour_adultes" />
      </div>
      <nav class="nav_right">
      <li>
      <a href="../index.php" title="accueil">ACCUEIL
      </a>
      </li>
      <li>
      <a href="../page_principal/exercices.php" title="exercices">EXERCICES
      </a>
      </li>
      <li>
      <a href="../page_principal/livres.php" title="livres">LIVRES
      </a>
      </li>
      <li>
      <a href="../page_principal/audio.php" style="color:#54d1cd;" title="audio">AUDIO
      </a>
      </li>
      <li>
      <a href="../page_principal/contact.php" title="contact">CONTACT
      </a>
      </div>

      </header>
      <div id="content">
      <br />
      <section>

      <figure style="display:inline-block;border:none;padding:1px;"><img width="390" height="580" style="margin:55px 0 60px 250px;" src="" alt=""><img width="960" height="800" style="margin:55px 0 0 -280px;" src="../img-audio-1/L1-47.png" alt=""><img width="390" height="580" style="margin:55px 0 60px 260px;" src="" alt=""><img width="960" height="800"style="margin:55px 0 -50px -280px;" src="" alt=""><img width="940" height="800"style="margin:25px 0 50px 250px;" src="" alt=""><img width="380" height="600" style="margin:25px 0 90px 240px;" src="" alt=""><img width="940" height="800" style="margin:25px 0 50px 200px;" src="" alt=""><img width="380" height="600" style="margin:25px 0 90px 40px;" src="" alt=""><img width="390" height="580" style="margin:55px 0 60px 250px;" src="" alt=""><img width="960" height="800" style="margin:55px 0 0 -280px;" src="../img-audio-1/L1-47.png" alt=""><img width="390" height="580" style="margin:55px 0 60px 260px;" src="" alt=""><img width="960" height="800"style="margin:55px 0 -50px -280px;" src="" alt=""><img width="940" height="800"style="margin:25px 0 50px 250px;" src="" alt=""><img width="380" height="600" style="margin:25px 0 90px 240px;" src="" alt=""><img width="940" height="800" style="margin:25px 0 50px 200px;" src="" alt=""><img width="380" height="600" style="margin:25px 0 90px 40px;" src="" alt=""><img width="390" height="580" style="margin:55px 0 60px 250px;" src="" alt=""><img width="960" height="800" style="margin:55px 0 0 -280px;" src="../img-audio-1/L1-47.png" alt=""><img width="390" height="580" style="margin:55px 0 60px 260px;" src="" alt=""><img width="960" height="800"style="margin:55px 0 -50px -280px;" src="" alt=""><img width="940" height="800"style="margin:25px 0 50px 250px;" src="" alt=""><img width="380" height="600" style="margin:25px 0 90px 240px;" src="" alt=""><img width="940" height="800" style="margin:25px 0 50px 200px;" src="" alt=""><img width="380" height="600" style="margin:25px 0 90px 40px;" src="" alt=""><img width="390" height="580" style="margin:55px 0 60px 250px;" src="" alt=""><img width="960" height="800" style="margin:55px 0 0 -280px;" src="../img-audio-1/L1-47.png" alt=""><img width="390" height="580" style="margin:55px 0 60px 260px;" src="" alt=""><img width="960" height="800"style="margin:55px 0 -50px -280px;" src="" alt=""><img width="940" height="800"style="margin:25px 0 50px 250px;" src="" alt=""><img width="380" height="600" style="margin:25px 0 90px 240px;" src="" alt=""><img width="940" height="800" style="margin:25px 0 50px 200px;" src="" alt=""><img width="380" height="600" style="margin:25px 0 90px 40px;" src="" alt=""><img width="390" height="580" style="margin:55px 0 60px 250px;" src="" alt=""><img width="960" height="800" style="margin:55px 0 0 -280px;" src="../img-audio-1/L1-47.png" alt=""><img width="390" height="580" style="margin:55px 0 60px 260px;" src="" alt=""><img width="960" height="800"style="margin:55px 0 -50px -280px;" src="" alt=""><img width="940" height="800"style="margin:25px 0 50px 250px;" src="" alt=""><img width="380" height="600" style="margin:25px 0 90px 240px;" src="" alt=""><img width="940" height="800" style="margin:25px 0 50px 200px;" src="" alt=""><img width="380" height="600" style="margin:25px 0 90px 40px;" src="" alt=""><img width="390" height="580" style="margin:55px 0 60px 250px;" src="" alt=""><img width="960" height="800" style="margin:55px 0 0 -280px;" src="../img-audio-1/L1-47.png" alt=""><img width="390" height="580" style="margin:55px 0 60px 260px;" src="" alt=""><img width="960" height="800"style="margin:55px 0 -50px -280px;" src="" alt=""><img width="940" height="800"style="margin:25px 0 50px 250px;" src="" alt=""><img width="380" height="600" style="margin:25px 0 90px 240px;" src="" alt=""><img width="940" height="800" style="margin:25px 0 50px 200px;" src="" alt=""><img width="380" height="600" style="margin:25px 0 90px 40px;" src="" alt=""><img width="390" height="580" style="margin:55px 0 60px 250px;" src="" alt=""><img width="960" height="800" style="margin:55px 0 0 -280px;" src="../img-audio-1/L1-47.png" alt=""><img width="390" height="580" style="margin:55px 0 60px 260px;" src="" alt=""><img width="960" height="800"style="margin:55px 0 -50px -280px;" src="" alt=""><img width="940" height="800"style="margin:25px 0 50px 250px;" src="" alt=""><img width="380" height="600" style="margin:25px 0 90px 240px;" src="" alt=""><img width="940" height="800" style="margin:25px 0 50px 200px;" src="" alt=""><img width="380" height="600" style="margin:25px 0 90px 40px;" src="" alt=""><img width="390" height="580" style="margin:55px 0 60px 250px;" src="" alt=""><img width="960" height="800" style="margin:55px 0 0 -280px;" src="../img-audio-1/L1-47.png" alt=""><img width="390" height="580" style="margin:55px 0 60px 260px;" src="" alt=""><img width="960" height="800"style="margin:55px 0 -50px -280px;" src="" alt=""><img width="940" height="800"style="margin:25px 0 50px 250px;" src="" alt=""><img width="380" height="600" style="margin:25px 0 90px 240px;" src="" alt=""><img width="940" height="800" style="margin:25px 0 50px 200px;" src="" alt=""><img width="380" height="600" style="margin:25px 0 90px 40px;" src="" alt=""></figure><audio style="display:inline-block;margin-left:0;margin-bottom:80px;margin-top:-50px;" controls preload="auto"><source src="" type="audio/mp3"/><source src="" type="audio/mp3"/><source src="../mp3/page47.mp3" type="audio/mp3"/><source src="" type="audio/mp3"/></audio><div style="float:left;margin-left:850px; margin-top:40px; margin-bottom:10px;"><a href="" download><img style="width="76"; height="76" src="../img/bouton-telecharger.png"></a><a href="" download><img style="width="76"; height="76" src="../img/bouton-telecharger.png"></a><a href="../mp3/page47.mp3" download><img style="width="76"; height="76" src="../img/bouton-telecharger.png"></a><a href="" download><img style="width="76"; height="76" src="../img/bouton-telecharger.png"></a></div><div style="float:left;width:150px; height:80px; margin:-65px 0 0 710px;"><a style="padding:1em 1.5em .7em 1.5em;border:1px solid #000;text-decoration:none;background:#fff;font-family:notoserif;font-weight:bold;color:#000;" href="http://s642262600.onlinehome.fr//index.php?img=..%2Fimg%2Flivre_1.jpg&prix=18.90&livre_1=ACHETER" >ACHETER</a></div> </section>

      </div>
      <!--------------content------>
      <footer class="footer_color">
      <div class="info_left foot_info_left">
      <p>Réalisation du site internet:
      <a style="font-size:1.3em;" href="../page_principal/contact_nills.php">Nilsweb
      </a>
      </p>
      <p>&copy - Le français pour adultes - 2016 - Tous droits réservés.
      </p>
      </div>
      <div class="info_left foot_info_right">
      <li class="info-border">
      <a href="contact.php">contact
      </a>
      </li>
      <li class="info-border">
      <a href="../page_principal/mention.php">Mention légales / Condition générales de ventes
      </a>
      </li>
      </div>
      </footer>
      </div>
      <!--------------wrapper------>
      <script src="js/viewportchecker.js">
      </script>
      <script type="text/javascript">
      jQuery(document).ready(function() {
      jQuery('.post').addClass("hidden").viewportChecker({
      classToAdd: 'visible animated fadeInDown', // Class to add to the elements when they are visible
      offset: 100
      }
      );
      }
      );
      </script>
      <script type="text/javascript">
      $(function() {
      $('a[href=#header]').click(function(){
      $('html').animate({
      scrollTop:0}
      , 'slow');
      return false;
      }
      );
      }
      );
      </script>
      <script type="text/javascript">
      var vid = document.getElementById("audio");
      function playVid(id) {
      var vid = document.getElementById(id);
      vid.play(id);
      }
      function pauseVid() {
      vid.pause();
      }
      </script>
      <script type="text/javascript">
      var vid = document.getElementById("son");
      function playVid(id) {
      var vid = document.getElementById(id);
      vid.play(id);
      }
      function pauseVid() {
      vid.pause();
      }
      </script>
      <script type="text/javascript">
      var vid = document.getElementById("son_1");
      function playVid(id) {
      var vid = document.getElementById(id);
      vid.play(id);
      }
      function pauseVid() {
      vid.pause();
      }
      </script>
      <script type="text/javascript">
      var vid = document.getElementById("son_2");
      function playVid(id) {
      var vid = document.getElementById(id);
      vid.play(id);
      }
      function pauseVid() {
      vid.pause();
      }
      </script>
      <script type="text/javascript">
      var vid = document.getElementById("son_3");
      function playVid(id) {
      var vid = document.getElementById(id);
      vid.play(id);
      }
      function pauseVid() {
      vid.pause();
      }
      </script>
      <script type="text/javascript">
      var vid = document.getElementById("son_4");
      function playVid(id) {
      var vid = document.getElementById(id);
      vid.play(id);
      }
      function pauseVid() {
      vid.pause();
      }
      </script>
      </body>
      </html>
    2. Contributeur
      @boni91pourquoi fais-tu une boucle qui crée 8 fois la même chose, 8 fois ceci, qui semble bizarrement incorrect (regarde ce que tu mets en src:
      <img width="390" height="580" style="margin:55px 0 60px 250px;" src="" alt="">
      <img width="960" height="800" style="margin:55px 0 0 -280px;" src="../img-audio-1/L1-47.png" alt="">
      <img width="390" height="580" style="margin:55px 0 60px 260px;" src="" alt="">
      <img width="960" height="800"style="margin:55px 0 -50px -280px;" src="" alt="">
      <img width="940" height="800"style="margin:25px 0 50px 250px;" src="" alt="">
      <img width="380" height="600" style="margin:25px 0 90px 240px;" src="" alt="">
      <img width="940" height="800" style="margin:25px 0 50px 200px;" src="" alt="">
      <img width="380" height="600" style="margin:25px 0 90px 40px;" src="" alt="">
  2. Modérateur
    Bonjour,

    Et au passage ... que vient faire ici ce
    break;
    ?*
    Pour rappel
    L'instruction break permet de sortir d'une structure for, foreach, while, do-while ou switch.

    et donc c'est normal qu'il s'arrête à la première itération de ta boucle.

    1. Contributeur
      peux-tu partager ton code php et le code source html de ta page?
      1. merci pour les réponses, mais je vient de tester et ça m affiche 1 image et le wrapper s’agrandit de la taille de 7 image, pourquoi?
        1. Modérateur
          for($i = 1; $i >= 8; $i--)
          Revois ta boucle for, elle est foireuse (un tutoriel de base est conseillé)
          1. Parceque le code ne RENTRE PLUS DU TOUT dans la boucle car $i = 1 donc $i n'EST PAS >= 8.

            Remplacer par for($i = 8; $i >= 1; $i--)