Jump to content

How to display every photo from a database? [closed]

Recommended Posts

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");

        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 }



Link to post
Share on other sites

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.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.