IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Mise en place de boucles


Sujet :

Langage PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre régulier
    Homme Profil pro
    Lycéen
    Inscrit en
    Mai 2017
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Mai 2017
    Messages : 4
    Par défaut Mise en place de boucles
    Bonjour,

    Je dois créer un tableau contenant des boucles "foreach" mais je ne sais pas où les placer. Dois-je les mettre au début du tableau ou en mettre une par ligne ?

    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
    <?php
     
    if(!empty($_POST['H1[]'])&&!empty($POST['H2[]'])&&!empty($POST['H3[]'])&&!empty($POST['H4[]'])&&!empty($POST['M1/H5[]'])&&!empty($POST['M2/H6[]'])&&!empty($POST['H7[]'])&&!empty($POST['H8[]'])&&!empty($POST['H9[]'])&&!empty($POST['H10[]'])&&!empty($POST['H11[]'])&&!empty($POST['H12[]']))
    {
    echo 'Vos disponibilites sont :<br />';
    foreach($_POST['H1[]'] as $val1)
    {
    echo $val1,'<br />';
    }
    foreach($_POST['H2[]'] as $val2)
    {
    echo $val2,'<br />';
    }
    foreach($_POST['H3[]'] as $val3)
    {
    echo $val3,'<br />';
    }
    foreach($_POST['H4[]'] as $val4)
    {
    echo $val4,'<br />';
    }
    foreach($_POST['H5[]'] as $val5)
    {
    echo $val5,'<br />';
    }
    foreach($_POST['H6[]'] as $val6)
    {
    echo $val6,'<br />';
    }
    foreach($_POST['H7[]'] as $val7)
    {
    echo $val7,'<br />';
    }
    foreach($_POST['H8[]'] as $val8)
    {
    echo $val8,'<br />';
    }
    foreach($_POST['H9[]'] as $val9)
    {
    echo $val9,'<br />';
    }
    foreach($_POST['H10[]'] as $val10)
    {
    echo $val10,'<br />';
    }
    foreach($_POST['H11[]'] as $val11)
    {
    echo $val11,'<br />';
    }
    foreach($_POST['H12[]'] as $val12)
    {
    echo $val12,'<br />';
    }
    echo '<br />
    Ecrire d"autres horaires : <a href="calendrier.php">Revenir a la page d"avant</a>';
    }
    else
    {
    echo 'Horaires disponibles pour les terminales
    <br /><br />
    <form action="calendrier2.php" method="post">
    <style type="text/css">
    .tg  {border-collapse:collapse;border-spacing:0;}
    .tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
    .tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
    .tg .tg-yw4l{vertical-align:top}
    </style>
    <table class="tg">
    
      <tr>
        <th class="tg-031e">Horaires</th>
        <th class="tg-031e">Lundi</th>
        <th class="tg-031e">Mardi</th>
        <th class="tg-031e">Mercredi</th>
        <th class="tg-031e">Jeudi</th>
        <th class="tg-yw4l">Vendredi</th>
      </tr>
      
      <tr>
        <td class="tg-031e">H1</td>
        <td class="tg-031e"><INPUT type="checkbox" name=H1[] value="Lundi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H1[] value="Mardi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H1[] value="Mercredi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H1[] value="Jeudi"></td>
        <td class="tg-yw4l"><INPUT type="checkbox" name=H1[] value="Vendredi"></td>
      </tr>
      <tr>
        <td class="tg-yw4l">H2</td>
        <td class="tg-yw4l"><INPUT type="checkbox" name=H2[] value="Lundi"></td>
        <td class="tg-yw4l"><INPUT type="checkbox" name=H2[] value="Mardi"></td>
        <td class="tg-yw4l"><INPUT type="checkbox" name=H2[] value="Mercredi"></td>
        <td class="tg-yw4l"><INPUT type="checkbox" name=H2[] value="Jeudi"></td>
        <td class="tg-yw4l"><INPUT type="checkbox" name=H2[] value="Vendredi"></td>
      </tr>
      <tr>
        <td class="tg-031e">H3</td>
        <td class="tg-031e"><INPUT type="checkbox" name=H3[] value="Lundi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H3[] value="Mardi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H3[] value="Mercredi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H3[] value="Jeudi"></td>
        <td class="tg-yw4l"><INPUT type="checkbox" name=H3[] value="Vendredi"></td>
      </tr>
      <tr>
        <td class="tg-031e">H4</td>
        <td class="tg-031e"><INPUT type="checkbox" name=H4[] value="Lundi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H4[] value="Mardi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H4[] value="Mercredi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H4[] value="Jeudi"></td>
        <td class="tg-yw4l"><INPUT type="checkbox" name=H4[] value="Vendredi"></td>
      </tr>
      <tr>
        <td class="tg-031e">M1/H5</td>
        <td class="tg-031e"><INPUT type="checkbox" name=H5[] value="Lundi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H5[] value="Mardi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H5[] value="Mercredi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H5[] value="Jeudi"></td>
        <td class="tg-yw4l"><INPUT type="checkbox" name=H5[] value="Vendredi"></td>
      </tr>
      <tr>
        <td class="tg-031e">M2/H6</td>
        <td class="tg-031e"><INPUT type="checkbox" name=H6[] value="Lundi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H6[] value="Mardi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H6[] value="Mercredi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H6[] value="Jeudi"></td>
        <td class="tg-yw4l"><INPUT type="checkbox" name=H6[] value="Vendredi"></td>
      </tr>
      <tr>
        <td class="tg-yw4l">H7</td>
        <td class="tg-031e"><INPUT type="checkbox" name=H7[] value="Lundi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H7[] value="Mardi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H7[] value="Mercredi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H7[] value="Jeudi"></td>
        <td class="tg-yw4l"><INPUT type="checkbox" name=H7[] value="Vendredi"></td>
      </tr>
      <tr>
        <td class="tg-yw4l">H8</td>
        <td class="tg-031e"><INPUT type="checkbox" name=H8[] value="Lundi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H8[] value="Mardi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H8[] value="Mercredi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H8[] value="Jeudi"></td>
        <td class="tg-yw4l"><INPUT type="checkbox" name=H8[] value="Vendredi"></td>
      </tr>
      <tr>
        <td class="tg-yw4l">H9</td>
        <td class="tg-031e"><INPUT type="checkbox" name=H9[] value="Lundi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H9[] value="Mardi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H9[] value="Mercredi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H9[] value="Jeudi"></td>
        <td class="tg-yw4l"><INPUT type="checkbox" name=H9[] value="Vendredi"></td>
      </tr>
      <tr>
        <td class="tg-yw4l">H8/H10</td>
        <td class="tg-031e"><INPUT type="checkbox" name=H10[] value="Lundi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H10[] value="Mardi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H10[] value="Mercredi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H10[] value="Jeudi"></td>
        <td class="tg-yw4l"><INPUT type="checkbox" name=H10[] value="Vendredi"></td>
      </tr>
      <tr>
        <td class="tg-yw4l">S1/H11</td>
        <td class="tg-031e"><INPUT type="checkbox" name=H11[] value="Lundi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H11[] value="Mardi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H11[] value="Mercredi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H11[] value="Jeudi"></td>
        <td class="tg-yw4l"><INPUT type="checkbox" name=H11[] value="Vendredi"></td>
      </tr>
      <tr>
        <td class="tg-yw4l">S2/H12</td>
        <td class="tg-031e"><INPUT type="checkbox" name=H12[] value="Lundi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H12[] value="Mardi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H12[] value="Mercredi"></td>
        <td class="tg-031e"><INPUT type="checkbox" name=H12[] value="Jeudi"></td>
        <td class="tg-yw4l"><INPUT type="checkbox" name=H12[] value="Vendredi"></td>
      </tr>
    </table>
    <input class="btn" name="Connexion" value=" VALIDER " type="submit">

  2. #2
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    déjà, utilise la bonne syntaxe
    • $_POST['H1[]']
    • $_POST['H1']

    • <INPUT type="checkbox" name=H1[] value="Lundi">
    • <input type="checkbox" name="H1[]" value="Lundi" />


    Et ça, ça sort d'où ?
    • ...$POST['M1/H5[]'])...($POST['M2/H6[]')... ??



    Ensuite, améliore l'indentation de ton code (tabulations, espaces,...), on y verra plus clair.

  3. #3
    Invité
    Invité(e)
    Par défaut
    Avec un peu de réflexion, on peut largement simplifier ce code.

    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
    <form method="post">
    <table>
      <tr>
        <th class="tg-031e">H</th>
        <th class="tg-031e">Lundi</th>
        <th class="tg-031e">Mardi</th>
        <th class="tg-031e">Mercredi</th>
        <th class="tg-031e">Jeudi</th>
        <th class="tg-yw4l">Vendredi</th>
      </tr>
      <tr>
        <td class="tg-031e">H1</td>
        <td class="tg-031e"><input type="checkbox" name="H[1][]" value="Lundi" /></td>
        <td class="tg-031e"><input type="checkbox" name="H[1][]" value="Mardi" /></td>
        <td class="tg-031e"><input type="checkbox" name="H[1][]" value="Mercredi" /></td>
        <td class="tg-031e"><input type="checkbox" name="H[1][]" value="Jeudi" /></td>
        <td class="tg-yw4l"><input type="checkbox" name="H[1][]" value="Vendredi" /></td>
      </tr>
      <tr>
        <td class="tg-yw4l">H2</td>
        <td class="tg-yw4l"><input type="checkbox" name="H[2][]" value="Lundi" /></td>
        <td class="tg-yw4l"><input type="checkbox" name="H[2][]" value="Mardi" /></td>
        <td class="tg-yw4l"><input type="checkbox" name="H[2][]" value="Mercredi" /></td>
        <td class="tg-yw4l"><input type="checkbox" name="H[2][]" value="Jeudi" /></td>
        <td class="tg-yw4l"><input type="checkbox" name="H[2][]" value="Vendredi" /></td>
      </tr>
      <tr>
        <td class="tg-yw4l">H2</td>
        <td class="tg-yw4l"><input type="checkbox" name="H[3][]" value="Lundi" /></td>
        <td class="tg-yw4l"><input type="checkbox" name="H[3][]" value="Mardi" /></td>
        <td class="tg-yw4l"><input type="checkbox" name="H[3][]" value="Mercredi" /></td>
        <td class="tg-yw4l"><input type="checkbox" name="H[3][]" value="Jeudi" /></td>
        <td class="tg-yw4l"><input type="checkbox" name="H[3][]" value="Vendredi" /></td>
      </tr>
    </table>
    	<input type="submit" value="OK" />
    </form>
    On récupère alors UN SEUL array : $_POST['H']
    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
    <?php
    if( !empty($_POST['H']) )
    {
    	$H_array = $_POST['H'];
     
    	echo 'Vos disponibilites sont :<br />';
    	foreach( $H_array as $i => $Hi )
    	{
    		foreach( $Hi as $key => $H )
    		{
    			echo 'H'.$i.'-'.$key.' : '.$H.'<br />';
    		}
    		echo '---------<br />';
    	}	
    }
    ?>

  4. #4
    Membre régulier
    Homme Profil pro
    Lycéen
    Inscrit en
    Mai 2017
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Mai 2017
    Messages : 4
    Par défaut
    SUPER MERCI !!!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. La mise en place d'une boucle
    Par brevi dans le forum Langage
    Réponses: 3
    Dernier message: 10/11/2014, 13h45
  2. [DEV][AppleScript] mise en place d'une boucle
    Par zoozbiro dans le forum AppleScript
    Réponses: 6
    Dernier message: 04/03/2009, 10h06
  3. [C#] Mise en place d'un site multilingue
    Par regbegpower dans le forum ASP.NET
    Réponses: 6
    Dernier message: 19/03/2004, 19h15
  4. mise en place serveur web intranet
    Par gui4593 dans le forum Installation
    Réponses: 7
    Dernier message: 01/01/2004, 18h18
  5. Mise en place d'index....??
    Par liv dans le forum Requêtes
    Réponses: 6
    Dernier message: 18/12/2003, 11h04

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo