Logo Luan Morina
Display a comma after each value, except after the last one
White Christmas, Rock Around the Clock, My Heart Will Go On, Nothing Compares 2 U, Hey Jude, (Everything I Do) I Do it For You, I Will Always Love You, Another Brick in the Wall (part 2), Flashdance... What a Feeling, (I Can't Get No) Satisfaction, Candle in the Wind '97, Gangsta's Paradise, Lose Yourself, Believe, Yeah!, Let it Be, A Whiter Shade of Pale, Stayin' Alive, Bleeding Love, Every Breath You Take

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 song_title FROM top_5000_songs ORDER BY popularity DESC LIMIT 0, 20";
$result = $conn -> query($sql);
if ($result -> num_rows > 0) {
$count_results = mysqli_num_rows($result); 
$count_titles = 0; 

while ($row = $result -> fetch_assoc()) {
if (++$count_titles == $count_results) {
echo "" . $row["song_title"] . "";  // last row
} else {
echo "" . $row["song_title"] . ", ";
} 

}
} 
else {
echo "No records found";
}
$conn -> close();
?>
   Comma after each record, except after the last one