0

Everything is coming from a PDO and is well displaying with the exception of the image. I wrote the folder's path in the DB as if it was written after a src=

As a beginner in php, i'm wondering if it's the good way to display a picture

EDIT: images are in jpg, console shows a "404" but with the good path

<?php
try {
    $bdd = new PDO(/*the pdo works*/);
}
catch(Exception $e)
{
        die('Erreur : '.$e->getMessage());
}
$reponse = $bdd->query('SELECT * FROM equipepedagogique');//where the picture is
?>
 <div class="enseignants"><!--grid-->
            <!--case-->
            <?php 
            while ($donnees=$reponse->fetch())
            foreach ($donnees as $donnee) { 
                $img=$donnees['photo'];
                $nom=$donnees['name'];
                $prenom=$donnees['surname'];
                $fonction=$donnees['fonction'];?>
            <div class="enseignant">
                <a href="">
                    <img src="<?php echo $img?>" alt="" class="photoEnseignant">
                </a>
                <h1 style="margin-left:auto;margin-right:auto;"><?= $prenom .' '. $nom ?></h1>
                <p><?= $fonction ?></p>
            </div>
            <?php } ?>
        </div>

3
  • Is $img a path or a binary value? if it is a binary value print sample value you read from database in the question. Commented Jun 24, 2021 at 9:28
  • 1
    What does $img contain? Commented Jun 24, 2021 at 9:30
  • $img is supposed to display the path of the picture in the folder from the database, stocked with a TEXT type. Commented Jun 24, 2021 at 9:36

1 Answer 1

0
<?php
try {
    $bdd = new PDO(/*the pdo works*/);
}
catch(Exception $e)
{
        die('Erreur : '.$e->getMessage());
}
$reponse = $bdd->query('SELECT * FROM equipepedagogique');//where the picture is
?>
 <div class="enseignants"><!--grid-->
            <!--case-->
            <?php 
            ***while ($donnees=$reponse->fetch())*** **//while($donnees=$reponse->mysql_fetch_array())**
            foreach ($donnees as $donnee) { 
                $img=$donnees['photo'];
                $nom=$donnees['name'];
                $prenom=$donnees['surname'];
                $fonction=$donnees['fonction'];?>
            <div class="enseignant">
                <a href="">
                    <img src="<?php echo $img?>" alt="" class="photoEnseignant">
                </a>
                <h1 style="margin-left:auto;margin-right:auto;"><?= $prenom .' '. $nom ?></h1>
                <p><?= $fonction ?></p>
            </div>
            <?php } ?>
        </div>
Sign up to request clarification or add additional context in comments.

1 Comment

thanks , but it doesn't work. but $nom, $prenom and $fonction are displayed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.