0

I am having trouble displaying an image in my mysql database uploaded as a blob.

I have tried echoing the image. All other categories are displayed except the image.

$query = $handler->query('SELECT * FROM articles');
$results = $query->fetchAll(PDO::FETCH_ASSOC);

for ($i=0; $i < count($results); $i++) { 
  echo '<div class="col-md-4 col-xs-12 col-sm-12 height-news">';
  echo '<p class="news-title">'.$results[$i]['headline'].'<br>'.'</p>';
  echo '<img class="news-img" '.'src="'.$results[$i]['logo'].'">'.'</img>'.'<br>';
  echo '<p class="news-time">'.$results[$i]['date'].'<br>'.'</p>';
  echo '<p class="news-body">'.$results[$i]['text'].'<br>'.'</p>'.'</div>';
}

?>

Using this code I get this error:

Notice: Undefined variable: result in C:\xampp\htdocs\deeplake6\news.php on line 129

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Diced Mango
  • 69
  • 1
  • 5

1 Answers1

-1

try this ..

echo '<img src="data:image/jpeg;base64,'.base64_encode( $results[$i]['logo'] ).'" />';

the mysql link file :: https://pastebin.com/0bdCCw8P

and this my own test Code :

$dsn = 'mysql:host=localhost;dbname=stack1'; 
    $username = 'root'; 
    $pwd=''; 
    try {
        $db = new PDO($dsn, $username, $pwd);
    }
    catch (PDOException $e) {
        $error_message = $e->getMessage();
        echo "this is displayed because an error was found";
        exit();
}




$query = $db->prepare("SELECT * FROM articles");
$query->execute();
$result = $query->fetchall();


//echo $result['0']['2'] ;


echo '<img src="data:image/jpeg;base64,'.base64_encode( $result['0']['2'] ).'"/>';

die ; 
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Houssem Cherif
  • 221
  • 1
  • 11