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

PHP & Base de données Discussion :

cocher une image suivant la bdd [MySQL]


Sujet :

PHP & Base de données

  1. #1
    Membre régulier
    Homme Profil pro
    Inscrit en
    Octobre 2004
    Messages
    514
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2004
    Messages : 514
    Points : 107
    Points
    107
    Par défaut cocher une image suivant la bdd
    Bonjour voilà je suis un peux bête sur ce point j'essaye de cocher une des 7 images suivant la donnée sortant de la bdd
    j'ai essayé avec un switch. mais cela ne fonction pas une petite idée svp?

    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
    <div class="div2">';
     
    echo'<table style="width:205px;">
      <tr>
        <td style="width:165px;"><img src="design/A.png" width="160" height="35" border="0" /></td>
        <td style="width:35px;">';
    switch ($result->peb){
    	case "A":      
    	echo'<img src="design/v.png" width="28" height="28" border="0" />
    	</td>
      </tr>
      <tr>
        <td><img src="design/B.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/C.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/D.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/E.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/F.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/G.png" width="160" height="35" border="0" /></td>
        <td></td>
        </tr>
        </table>';
        break;  
    echo'</td>
      </tr>
      <tr>
        <td><img src="design/A.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/B.png" width="160" height="35" border="0" /></td>
        <td>';
    	case "B":      
    	echo'<img src="design/v.png" width="28" height="28" border="0" />	
    	</td>
      </tr>
      <tr>
        <td><img src="design/C.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/D.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/E.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/F.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/G.png" width="160" height="35" border="0" /></td>
        <td></td>
        </tr>
        </table>';
        break; 
    echo'</td>
      </tr>
      <tr>
        <td><img src="design/A.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/B.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/C.png" width="160" height="35" border="0" /></td>
        <td>';
    	case "C":      
    	echo'<img src="design/v.png" width="28" height="28" border="0" />	
    	</td>
      </tr>
      <tr>
        <td><img src="design/D.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/E.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/F.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/G.png" width="160" height="35" border="0" /></td>
        <td></td>
        </tr>
        </table>';
        break;  
    echo'</td>
      </tr>
      <tr>
        <td><img src="design/A.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/B.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/C.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/D.png" width="160" height="35" border="0" /></td>
        <td>';
    	case "D":      
    	echo'<img src="design/v.png" width="28" height="28" border="0" />	
    	</td>
      </tr>
      <tr>
        <td><img src="design/E.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/F.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/G.png" width="160" height="35" border="0" /></td>
        <td></td>
        </tr>
        </table>';
        break; 
    echo'</td>
      </tr>
      <tr>
        <td><img src="design/A.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/B.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/C.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/D.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/E.png" width="160" height="35" border="0" /></td>
        <td>';
    	case "E":      
    	echo'<img src="design/v.png" width="28" height="28" border="0" />	
    	</td>
      </tr>
      <tr>
        <td><img src="design/F.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/G.png" width="160" height="35" border="0" /></td>
        <td></td>
        </tr>
        </table>';
        break; 
    echo'</td>
      </tr>
      <tr>
        <td><img src="design/A.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/B.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/C.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/D.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/E.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/F.png" width="160" height="35" border="0" /></td>
        <td>';
    	case "F":      
    	echo'<img src="design/v.png" width="28" height="28" border="0" />	
    	</td>
      </tr>
      <tr>
        <td><img src="design/G.png" width="160" height="35" border="0" /></td>
        <td></td>
        </tr>
        </table>';
        break; 
    echo'</td>
      </tr>
      <tr>
        <td><img src="design/A.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/B.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/C.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/D.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/E.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/F.png" width="160" height="35" border="0" /></td>
        <td></td>
      </tr>
      <tr>
        <td><img src="design/G.png" width="160" height="35" border="0" /></td>
        <td>';
    	case "B":      
    	echo'<img src="design/v.png" width="28" height="28" border="0" />	
    	</td>
        </tr>
        </table>';
        break; }
     
    }
    echo'</div>';
    ?>

  2. #2
    Membre expérimenté
    Homme Profil pro
    Développeur C++
    Inscrit en
    Avril 2012
    Messages
    771
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur C++
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2012
    Messages : 771
    Points : 1 631
    Points
    1 631
    Par défaut
    Bonjour,

    dans ton switch tu écrit du code qui ne sera jamais exécuté,

    quand tu fait :
    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
    <?php
    switch($result->peb){
        case 'A':
            echo 'A1';
        break;
     
        echo 'A2';
     
        case 'B':
            echo 'B1';
        break;
     
        echo 'B2'
     
        case 'C'
            echo 'C1';
        break;
     
        echo 'C2';
    }
    ?>
    les instructions echo 'A2', echo 'B2', echo 'C2' ne seront jamais exécuté car ne sont dans aucun case.

    ensuite pour ton problème j'avoue ne pas comprendre ce que tu a voulu faire avec ton code,

    si j'ai bien compris tu a un tableau avec plusieurs image A, B, C, D, E, F et G et selon une information de ta BDD tu veut ajouter une image v.png à coté de celle ci ?

    le plus simple est si ton tableau est statique, ton template est écrit en dur et n'est voué à ne jamais être modifié alors le plus simple serait :
    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
    <?php
    //Tu construit ton tableau
    //Et tu teste avec un if pour chaque cas
    ?>
    <table>
        <tr>
             <td><img src="design/A.png" width="160" height="35" border="0" /></td>
            <td><?php if($result->peb == 'A'){ echo '<img src="design/v.png" width="28" height="28" border="0" />';} ?></td>
        </tr>
        <tr>
            <td><img src="design/B.png" width="160" height="35" border="0" /></td>
            <td><?php if($result->peb == 'B'){ echo '<img src="design/v.png" width="28" height="28" border="0" />';} ?></td>
        </tr>
        <tr>
            <td><img src="design/C.png" width="160" height="35" border="0" /></td>
            <td><?php if($result->peb == 'C'){ echo '<img src="design/v.png" width="28" height="28" border="0" />';} ?></td>
        </tr>
        <tr>
            <td><img src="design/D.png" width="160" height="35" border="0" /></td>
            <td><?php if($result->peb == 'D'){ echo '<img src="design/v.png" width="28" height="28" border="0" />';} ?></td>
        </tr>
        <tr>
            <td><img src="design/E.png" width="160" height="35" border="0" /></td>
            <td><?php if($result->peb == 'E'){ echo '<img src="design/v.png" width="28" height="28" border="0" />';} ?></td>
        </tr>
        <tr>
            <td><img src="design/F.png" width="160" height="35" border="0" /></td>
            <td><?php if($result->peb == 'F'){ echo '<img src="design/v.png" width="28" height="28" border="0" />';} ?></td>
        </tr>
        <tr>
            <td><img src="design/G.png" width="160" height="35" border="0" /></td>
            <td><?php if($result->peb == 'G'){ echo '<img src="design/v.png" width="28" height="28" border="0" />';} ?></td>
        </tr>
    </table>
     
    ?>
    Par contre si tu récupère les images dans une BDD il te suffit au moment de la construction de ton tableau d'ajouter l'image v.png.

    par exemple:
    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
    //Procédure de connexion à la BDD
    //...
    //La requête SQL qui va récupérer toutes les images dans la BDD
    $requete = $bdd->query('SELECT * from images');
     
    //On construit l'entête du tableau
    ?>
    <table>
        <tr>
            <th>nom Image</th>
            <th>Validé</th>
        </tr>
    <?php
    //Pour chaque image on ajoute une nouvelle ligne dans le tableau
    while( $resultat = $requete->fetch() ){
    echo '<tr>
            <td><img src="design/' . $resultat['nomImage'] . '" /></td>
            <td>';
            //$resultat['TAG'] correspond à la lettre que tu utilise 'A', 'B', ...
            if( $result->peb == $resultat['TAG'] ){
                echo '<img src="design/v.png" width="28" height="28" border="0" />';
            }
            echo '</td>
        </tr>';
    }
    </table>
    une réponse vous a permis d'avancer ?

  3. #3
    Membre régulier
    Homme Profil pro
    Inscrit en
    Octobre 2004
    Messages
    514
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2004
    Messages : 514
    Points : 107
    Points
    107
    Par défaut
    Merci la nuit porte conseil lol j'ai trouver par moi même Merci a tous de vos réponse

    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
    <?PHP
    		$select=mysql_query("SELECT * FROM annonce WHERE idA='".$_SESSION['detail']."'") or die(mysql_error());
    		if($result = mysql_fetch_object($select))
    		{
     
    echo'<table style="width:270px;"><b>
      <tr>
        <td style="width:120px;">Société ou Nom :</td>
        <td style="width:150px;">'.$result->nom.'</td>
      </tr>
      <tr>
        <td>Vendeur :</td>
        <td>'.$result->vendeur.'</td>
      </tr>
      <tr>
        <td>Adresse :</td>
        <td>'.$result->adresse.','.$result->numero.'/'.$result->boite.'</td>
      </tr>
      <tr>
        <td></td>
        <td>'.$result->cp.'&nbsp;&nbsp;,'.$result->ville.'</td>
      </tr>
      <tr>
        <td>Téléphone :</td>
        <td>'.$result->phone.'</td>
      </tr>
      <tr>
        <td>Prix :</td>
        <td>'.$result->prixb.'&nbsp;&euro;</td>
      </tr>
      <tr>
        <td>Cadastre :</td>
        <td>'.$result->prixc.'&nbsp;&euro;</td>
      </tr>
      <tr>
        <td>Chambre(s) :</td>
        <td>'.$result->ch.'</td>
      </tr>
      <tr>
        <td>Superficie Bien :</td>
        <td>'.$result->supb.'M²</td>
      </tr>
      <tr>
        <td>Superficie Terrain :</td>
        <td>'.$result->supc.'M²</td>
      </tr>
      <tr>
        <td>Libre :</td>
        <td>'.$result->libreq.'</td>
      </tr>  
    </b></table>';			
     
    echo'</div>
    <div class="div2">';
     
    echo'<table style="width:205px;">
      <tr>
        <td style="width:165px;"><img src="design/A.png" width="160" height="35" border="0" /></td>
        <td style="width:35px;">';if ($result->peb=="A"){echo'<img src="design/v.png" width="28" height="28" border="0">';}echo'</td>
      </tr>
      <tr>
        <td><img src="design/B.png" width="160" height="35" border="0" /></td>
        <td style="width:35px;">';if ($result->peb=="B"){echo'<img src="design/v.png" width="28" height="28" border="0">';}echo'</td>
      </tr>
      <tr>
        <td><img src="design/C.png" width="160" height="35" border="0" /></td>
        <td style="width:35px;">';if ($result->peb=="C"){echo'<img src="design/v.png" width="28" height="28" border="0">';}echo'</td>
      </tr>
      <tr>
        <td><img src="design/D.png" width="160" height="35" border="0" /></td>
        <td style="width:35px;">';if ($result->peb=="D"){echo'<img src="design/v.png" width="28" height="28" border="0">';}echo'</td>
      </tr>
      <tr>
        <td><img src="design/E.png" width="160" height="35" border="0" /></td>
        <td style="width:35px;">';if ($result->peb=="E"){echo'<img src="design/v.png" width="28" height="28" border="0">';}echo'</td>
      </tr>
      <tr>
        <td><img src="design/F.png" width="160" height="35" border="0" /></td>
        <td style="width:35px;">';if ($result->peb=="F"){echo'<img src="design/v.png" width="28" height="28" border="0">';}echo'</td>
      </tr>
      <tr>
        <td><img src="design/G.png" width="160" height="35" border="0" /></td>
        <td style="width:35px;">';if ($result->peb=="G"){echo'<img src="design/v.png" width="28" height="28" border="0">';}echo'</td>
      </tr>
    </table>';
     
    }
    echo'</div>';
    ?>

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

Discussions similaires

  1. [Upload] Enregistrer chemin d'une image dans ma BDD
    Par Erwan M. dans le forum Langage
    Réponses: 6
    Dernier message: 02/04/2008, 15h45
  2. [c#] recuper une image depuis sa BDD
    Par fally dans le forum C#
    Réponses: 3
    Dernier message: 20/03/2008, 10h30
  3. Réponses: 9
    Dernier message: 02/06/2007, 15h42
  4. Réponses: 5
    Dernier message: 21/01/2007, 19h31
  5. [VBA-E] inserer une image suivant état donné
    Par totoza dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 31/05/2006, 14h02

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