veks21 Posted March 23, 2021 Share Posted March 23, 2021 Hello. I want to display all photos from the database. The problem is that it displays nothing. I added a foreach loop in html but further it not display. I'am beginner, I hope someone help me where I make mistake. I care about separation logic from view. class photo_display { private $database; private $userData; public function __construct($database) { $this->database = $database; } public function display() { $query = $this->database->connect()->prepare("SELECT photo FROM photo"); $query->execute(); if ($query->rowcount()) { $row = $query->fetchAll(); } $this->userData = $row; } public function display_Photos(string $colName) { return (isset($this->userData[$colName])) ? $this->userData[$colName] : []; } } <div class='container-fluid bg-dark' id='profil'> <div class='row'> <div class=" col-12 col-sm-12 col-md-4 col-lg-4 col-xl-4 order-5 order-12 order-6 order-md-4"> <div class="row" id="margin"> <div class="col-xl-12 d-flex justify-content-center" id="test"> <?php foreach ($photo_display->display_Photos('photo') as $value) { ?> <img src ="<?php echo var_dump($value) ?>" />; <?php } ?> </div> </div> </div> Quote Link to comment https://forums.phpfreaks.com/topic/312366-how-to-display-every-photo-from-a-database-closed/ Share on other sites More sharing options...
Barand Posted March 23, 2021 Share Posted March 23, 2021 Where do create the instances of your database and photo_display classes? How are you storing the images. <img src needs to be a filename (or encoded data), not var_dump output. Quote Link to comment https://forums.phpfreaks.com/topic/312366-how-to-display-every-photo-from-a-database-closed/#findComment-1585320 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.