MySQL

Zoekresultaten weergeven

MySQL database zoekresultaten weergeven
<?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();
?>