View database data from

Asked

Viewed 113 times

0

I want to display several data on a page but it appears only one, when instead of appearing the image of each register for example it appears only that of a which is the latest record ever 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'];
}
 ?>

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 has been discontinued. use or PDO or Mysqli

Connection to PDO

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

Consultation PDO

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

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

}
  • 1

    When mysqli use this error: mysqli_query() expects at least 2 Parameters, 1 Given

  • 1

    is because it’s not just swapping mysql_for mysqli. use PDO and it’s even better. I’ll give you an example updating the answer

Browser other questions tagged

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