Petra Jakubcova
Petra Jakubcova

Reputation: 105

Problem displaying images from MySql database PDO

I got a problem while displaying the images from MySQL Database. When I load the page, only the empty image element is loaded but not the actual image coming from database. I think that php code is not correct.

<?php 

 //connection do db
require_once __DIR__.'/connect.php';

try{
     $stmt = $db->prepare('SELECT * FROM pictures');
     $stmt->execute();
     if($stmt->rowCount()>0)
     {
         while($row=$stmt->fetchColumn())
         {
             extract($row);
;         }
     } 

}catch (PDOEXception $ex){
    echo $ex;
}
?>
<img src="images/<?php echo $row['path']?>"> 

Upvotes: 0

Views: 60

Answers (1)

barbsan
barbsan

Reputation: 3458

You have to create <img> tags in while loop. Try:

while($row=$stmt->fetchColumn())
{
    extract($row);
    echo '<img src="images/'.$row['path'].'">'; 
}

Upvotes: 1

Related Questions