LizzyPooh
LizzyPooh

Reputation: 1345

Why is my images not appearing, when trying to get them from database

Hiya I am getting information from my database to present onto the webpage, everything is correct with connection as the information is present on the page.

But when it comes to the pictures they come up with a little box of where they are meant to be. Heres the code I have:

<?php
error_reporting(0);
require './db/connect.php';
include './includes/header.php';
?>

<h2>Production</h2>

<?php
if($result = $connection->query("SELECT * FROM Production")){
if($count = $result->num_rows){
      $Image = $rows['Image'];      
    while($row = $result->fetch_object()){
        echo '<pre>'.'<img class="productionimages" src="path/'.$Image.'" />',' '
                ,$row->ProductionName,' ',$row->ProductionType, '</pre>';
    }
    $result->free();
    }
}
     echo $result; 

include './includes/footer.php';
?>

Heres a picture below of what appears on the screen.

Problem I am having

Upvotes: 0

Views: 65

Answers (1)

CT14.IT
CT14.IT

Reputation: 1737

You need to set $Image within the while loop and $rows['Image'] should be $row->Image, like so.

<?php
if($result = $connection->query("SELECT * FROM Production")){
if($count = $result->num_rows){

    while($row = $result->fetch_object()){
        $Image = $row->Image;
        echo '<pre>'.'<img class="productionimages" src="path/'.$Image.'" />',' '
                ,$row->ProductionName,' ',$row->ProductionType, '</pre>';
    }
    $result->free();
    }
}
     echo $result; 

include './includes/footer.php';
?>

Upvotes: 1

Related Questions