AFFICHAGE PHOTO DANS UNE BOUCLE PHP (BDD)

Résolu
rdbn Messages postés 95 Date d'inscription   Statut Membre Dernière intervention   -  
rdbn Messages postés 95 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,
J'ai récupéré de ma base de donnée des infos concernant seulement 4 produits que j'ai affiché sur une page php en tableau. Il y a une colonne photo, sur ma base de donnée les infos de cette colonne sont seulement l'extension de celle-ci donc dans mon tableau je n'ai que leurs extensions.
Ce que je voudrais c'est savoir comment les remplacer par des images que j'ai dans un dossier, peut être leurs assigné un id pour chaque image...bon j'ai essayer j'ai pas réussie . Cependant j'ai réussi avec une seule image mais comme ceci est dans une boucle l'image apparaît sur tout les produits....

Voici le code :
<main>
    <!-- DEBUT corps du tableau: -->
      <div class="row justify-content-center p-3">
        <table class="col-10 table table-bordered shadow rounded mt-2">
          <thead>
              <tr class="table-secondary">
                  <th scope="col" class="font-weight-semi-bold h6 border-table-secondary border-bottom-0">Photo</th>
                  <th scope="col" class="font-weight-semi-bold h6 border-table-secondary border-bottom-0">ID</th>
                  <th scope="col" class="font-weight-semi-bold h6 border-table-secondary border-bottom-0">Référence</th>
                  <th scope="col" class="font-weight-semi-bold h6 border-table-secondary border-bottom-0">Libellé</th>
                  <th scope="col" class="font-weight-semi-bold h6 border-table-secondary border-bottom-0">Prix (€)</th>
                  <th scope="col" class="font-weight-semi-bold h6 border-table-secondary border-bottom-0">Stock</th>
                  <th scope="col" class="font-weight-semi-bold h6 border-table-secondary border-bottom-0">Couleur</th>
                  <th scope="col" class="font-weight-semi-bold h6 border-table-secondary border-bottom-0">Ajout</th>
                  <th scope="col" class="font-weight-semi-bold h6 border-table-secondary border-bottom-0">Modif</th>
                  <th scope="col" class="font-weight-semi-bold h6 border-table-secondary border-bottom-0">Bloqué</th>    
              </tr>       
          </thead>
          <tbody>
              <?php
                foreach($result as $produits){

                  if($produits['pro_bloque'] == true) {

                    $produits['pro_bloque'] = "bloque";
                } else {

                    $produits['pro_bloque'] = "";
                }
              ?>
                <tr>
                  <td class="bg-warning font-weight-light h6 border border-secondary"><img src="src/img/11.<?= $produits['pro_photo'] ?>" height="80" width="auto"></td>
                  <td class="table-secondary font-weight-light h6 border-secondary"><?= $produits['pro_id'] ?></td>
                  <td class="table-secondary font-weight-light h6 border-secondary"><?= $produits['pro_ref'] ?></td>
                  <td class="bg-warning font-weight-normmal h6 border-secondary text-uppercase"><u><a href="details_produits.php?id=<?= $produits['pro_id'] ?>"style=color:#FF0000><?= $produits['pro_libelle'] ?></a></u></td>
                  <td class="table-secondary font-weight-light h6 border-secondary"><?= $produits['pro_prix'] ?></td>
                  <td class="table-secondary font-weight-light h6 border-secondary"><?= $produits['pro_stock'] ?></td>
                  <td class="table-secondary font-weight-light h6 border-secondary"><?= $produits['pro_couleur'] ?></td>
                  <td class="table-secondary font-weight-light h6 border-secondary"><?= $produits['pro_d_ajout'] ?></td>
                  <td class="table-secondary font-weight-light h6 border-secondary"><?= $produits['pro_d_modif'] ?></td>
                  <td class="table-secondary font-weight-semi-bold h6 border-secondary"style=color:#FF0000><?= $produits['pro_bloque'] ?></td>
                </tr>
              <?php   
                }
              ?>
          </tbody>
        </table>
      </div>

    <!-- FIN corps du tableau: -->
    </main> 


j'ai essayer avec ceci assigné une photo par rapport à un id mais cela me met une erreur de syntaxe

                foreach($result as $produits){

                  if($produits['pro_id'] == 7) {
                    $produits['pro_photo'] = echo "<img src="src/img/11" height="80" width="auto">";
                  }

Configuration: Windows / Chrome 89.0.4389.90
A voir également:

1 réponse

yg_be Messages postés 23541 Date d'inscription   Statut Contributeur Dernière intervention   Ambassadeur 1 584
 
bonjour,
comment peux-tu déterminer l'image correspondant à chaque produit?
donne peut-être un exemple.
0
rdbn Messages postés 95 Date d'inscription   Statut Membre Dernière intervention  
 
Bonjour j'ai mis ceci juste avant je ne sais pas si vous l'avez vue
j'ai essayer avec ceci assigné une photo par rapport à un id mais cela me met une erreur de syntaxe

en gros dans ma boucle si l'id (que je connais ici) est vaut 7 (l'id correspondant au produit de bdd)
aura l'image correspondante récupéré de mon dossier

                foreach($result as $produits){

                  if($produits['pro_id'] == 7) {
                    $produits['pro_photo'] = echo "<img src="src/img/11" height="80" width="auto">";
                  }
0
yg_be Messages postés 23541 Date d'inscription   Statut Contributeur Dernière intervention   1 584 > rdbn Messages postés 95 Date d'inscription   Statut Membre Dernière intervention  
 
inutile de montrer ce code, explique plutôt, en français, comment trouver le nom du fichier pour un produit.
0
rdbn Messages postés 95 Date d'inscription   Statut Membre Dernière intervention   > yg_be Messages postés 23541 Date d'inscription   Statut Contributeur Dernière intervention  
 
je ne comprend pas vraiment ce que vous essayer de me dire
comment trouver le nom de l'image qui correspond au produit c'est ca ?
0
yg_be Messages postés 23541 Date d'inscription   Statut Contributeur Dernière intervention   1 584 > rdbn Messages postés 95 Date d'inscription   Statut Membre Dernière intervention  
 
oui, explique, en français, comment trouver le nom de l'image qui correspond au produit.
0
rdbn Messages postés 95 Date d'inscription   Statut Membre Dernière intervention   > yg_be Messages postés 23541 Date d'inscription   Statut Contributeur Dernière intervention  
 
bah c'est dans un dossier hors de la base de donnée et le nom je le connais puisque c'est moi qui peux le nommer par exemple j'ai une image d'une pelle que je nomme "pelle" donc je sais qu'elle correspondra à mon produit nommé "pelle"
0