Error fetching database images - PHP

Asked

Viewed 20 times

0

As imagens não aparecem na pagina

inserir a descrição da imagem aqui

<?php

    $banco = new mysqli("localhost", "root", "","bd");
    $sql = "SELECT arquivo FROM lojas";
    $resultado = $banco->query($sql);
    while($linha = mysqli_fetch_array($resultado)){
    $album[] = $linha;  
}

?>

<!DOCTYPE>
<html lang="pt-br">
<head>

<meta charset="utf-8">
<link rel = "stylesheet" type = "text/css" href = "style.php">
</head>
<body>
<header>    

<table>
<tr>
    <?php
        foreach($album as $foto){
    ?>
    <td>
        <img src="<?php echo "./imagens/".$foto["nome"] ?>" width="260" height="200"/>
        <td>
    <?php }
    ?>

    </tr>
</table>

  • We’d have to be one Hacker to find the structure of your table in the database to see the column names and make a correction in the declaration SELECT or in $foto["nome"] inside the foreach

1 answer

1


Not having enough information to make a proper diagnosis, first see if in this table, the image name is actually being saved in the 'name' column. Second, the query is only collecting data from the 'file' column of the store table. It would have to be:

$sql = "SELECT arquivo,nome FROM lojas";

Otherwise, the 'archive' column is where the file names are being saved, so php is wrong, so we would have:

<img src="<?php echo "./imagens/".$foto["arquivo"] ?>" width="260" height="200"/>
  • That solved it. Thanks! <img src="<? php echo ". /images/". $photo["file"] ? >" width="260" height="200"/>

  • You’re welcome. Always at your service :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.