How to organize Bdados results

Asked

Viewed 54 times

1

Hi, I’m doing a movie site and would like a help on that part.

After getting a connection to the BD, I want each record to appear within the grid that I made.

I’ll explain it better with pictures.

inserir a descrição da imagem aqui

Each film has its record containing every piece of information I wish to manipulate.

inserir a descrição da imagem aqui

Above shows how I call mine script PHP that contains the BD connection. but it shows the 2 records in the same place, wanted the film 1 to be at the location of the 1 and so on. follows the grid of layout!

inserir a descrição da imagem aqui

This is the PHP file

<?php 
$conecta = mysql_connect("127.0.0.1", "root", "") or print (mysql_error()); 
mysql_select_db("bd", $conecta) or print(mysql_error()); 


 $filmes = mysql_query("SELECT * FROM filmes");
    while($dados = mysql_fetch_array($filmes)){

         echo $dados['nome'] . "<br>";
         echo $dados['sinopse'] . "<br>";
         echo $dados['categoria'] . "<br>";

    }


?>
  • Gustavo, the OS does not accept PHP tags, try playing your example on the following site: http://phpfiddle.org/

  • This last snippet would be your get.php?

  • yes, he’s basically for connection.

  • Then you can assemble your structure within the while...

1 answer

5


The way you are doing, you will need to concatenate the HTML into the php file.

<?php 
$conecta = mysql_connect("127.0.0.1", "root", "") or print (mysql_error()); 
mysql_select_db("bd", $conecta) or print(mysql_error()); 

$filmes = mysql_query("SELECT * FROM filmes");
$size = 0;
while($dados = mysql_fetch_array($filmes)){
     if($size == 0)
         echo "<ul>";
     echo "<li>";
     echo $dados['nome'] . "<br>";
     echo $dados['sinopse'] . "<br>";
     echo $dados['categoria'] . "<br>";
     echo "</li>";
     if($size == 2)
         echo "</ul>";
     $size++;
     $size = $size == 3 ? 0 : $size;
}
?>

And in your HTML, change to:

<div><?php include("get.php"); ?></div>
  • 1

    WOW, kkkk, it looks magical! , it worked dude, perfectly! thank you very much.

  • I edited it to show 3 movies per line and then add a new line.

Browser other questions tagged

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