View database data

0

I want to display several data in a page but it only appears one, instead of appearing the image of each register for example it appears only the one of a which is the last one made.

                       

$query = "SELECT * FROM animestb LIMIT 20000";
$con = mysql_query($query) or die(mysql_error());

while ($row = mysql_fetch_array($con)) {
  $nome = $row['nome'];
  $link = $row['link'];
  $img = $row['img'];
  $id = $row['id'];
}
 ?>

    
asked by anonymous 26.05.2017 / 19:51

1 answer

0
$sql = $pdo->prepare("SELECT * FROM animestb");
$sql->execute();

while($ln = $sql->fetchObject()){
     echo "<img src='".$ln->img."'>"
}

Please do not use mysql_query it has been discontinued. use or PDO or Mysqli

PDO Connection

<?php
$conn = new PDO('mysql:host=localhost;dbname=meuBancoDeDados', $username, $password);
?>

PDO Inquiry

$sql = $conn->prepare("SELECT * FROM tabela");
$sql->execute();

while($ln = $sql->fetchObject()){

}
    
26.05.2017 / 19:55