How to display a specific image?

Asked

Viewed 922 times

4

I am making a system of films that register the poster of the film and I want that when generate the report with all the registered movies, it shows me the image of the poster saved in the bank and not the name of the image. I found a code that shows all the images in a table of the bank, but shows all of them below the other and in the report I want to show them separately, next to the name, for example:

Title.................. Director............... Poster

13: The player..... Gela Babluani.... Image

The code that I found on the Internet and am basing myself on it is as follows:

<?php

include ('config.php');

$sql = mysql_query("SELECT * FROM filmes ORDER BY nome_filme");

while ($filmes = mysql_fetch_object($sql)) {

echo "<img src='fotos/".$filmes->foto."' alt='Foto de exibição' /><br />";

?>

Table name in the database: movies Poster picture variable name: $photo Movie name variable name: $movie name

  • Hmm ,you can do inside that while, a table, where it will show the results correctly.

1 answer

3


I’d do it that way:

<?php
include ('config.php');
$sql = mysql_query("SELECT * FROM filmes ORDER BY nome_filme");

    echo "
    <table>
        <tr>
            <td>COD</td>
            <td>Título</td>
            <td>Diretor</td>
            <td>Imagem</td>
        </tr>
    ";
    while ($filmes = mysql_fetch_array($sql)) {
        echo "
        <tr>
            <td>".$filmes['id']."</td>
            <td>".$filmes['titulo']."</td>
            <td>".$filmes['diretor']."</td>
            <td><img src='fotos/".$filmes['foto']."'></td>
        </tr>
        ";
    }
    echo "</table>";
?>
  • gave error in a line: Fatal error: Cannot use Object of type stdClass as array in C: xampp htdocs Arquivos 3 bimestre Trabalho cadastro_filmeslst.php on line 221 Linha 221: <td>". $movies['id']." </td>

  • Yes, you need to adjust the fields right...

  • I’ve changed, try again.

Browser other questions tagged

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