Logo Luan Morina
Display MySQL table records

Here's a simple example how to display MySQL table records with PHP

<?php
$conn = new mysqli ("server", "user", "password", "database");
mysqli_set_charset ($conn, "utf8");
if ($conn -> connect_error) {
die ("Error: " . $conn->connect_error);
}
$sql = "SELECT * FROM top_5000_songs LIMIT 0, 40";
$result = $conn -> query($sql);
if ($result -> num_rows > 0) {
while ($row = $result -> fetch_assoc()) {
echo "<div>" . $row["song"] . " - " . $row["artist"] . "</div>";
}
} 
else {
echo "No records found";
}
$conn -> close();
?>
   Display MySQL table records with PHP