Logo Luan Morina
Display MySQL table records in a Bootstrap table
YearSong TitleArtist
1994SecretMadonna
1978Stayin' AliveBee Gees
1957Don't Forbid MePat Boone
2009Whatcha SayJason Derulo
1955Heart of StoneThe Fontane Sisters
1970PatchesClarence Carter
1989Listen to Your HeartRoxette
2009Tik-TocKe$ha
1993WeakSWV
1996Just a GirlNo Doubt
1993ShoopSalt-N-Pepa
1977After the Lovin'Engelbert Humperdinck
1979FireThe Pointer Sisters
1985I'm Your ManWham!
1989Don't Know MuchLinda Ronstadt & Aaron Neville
1950One Silver DollarEve Young
1978Ca Plane Pour MoiPlastic Bertrand
1977Ma BakerBoney M
2004SuperstarJamelia
1994ZombieThe Cranberries
1970Never Marry a Railroad ManShocking Blue
2012Hall Of FameThe Script & will.i.am
2002In My PlaceColdplay
1973Brother LouieStories
1994Right in the Night (Fall in Love With Music)Jam & Spoon
2005Almost HereBrian McFadden & Delta Goodrem
1980SailingChristopher Cross
1971SuperstarMurray Head
1984High EnergyEvelyn Thomas
1973MoneyPink Floyd
1986How Will I KnowWhitney Houston
1982The Day Before You CameAbba
2003IntuitionJewel
2004The Way You MoveOutKast
1984Dancing in the DarkBruce Springsteen
1943Pistol Packin' MamaAl Dexter & his Troopers
1995Exhale (Shoop Shoop)Whitney Houston
1990SacrificeElton John
2010DynamiteTaio Cruz
1955Unchained MelodyLes Baxter & his Orchestra
1953Vaya Con Dios (may God Be With You)Les Paul & Mary Ford
1973Mama LooLes Humphries Singers
1987My Baby Just Cares For MeNina Simone
2002Always On TimeJa Rule & Ashanti
1979I Want Your LoveChic
1990Crying in the RainA-Ha
1978Summer NightsJohn Travolta & Olivia Newton-John
1981One Day in Your LifeMichael Jackson
2003Not Gonna Get Ust.A.T.u.
1956A Woman in LoveFrankie Laine
1964PeopleBarbra Streisand
1975Make Me Smile (Come Up & See Me)Steve Harley & Cockney Rebel
1987Looking For a New LoveJody Watley
1922April ShowersAl Jolson
2002Cleanin' Out My ClosetEminem
1981Arthur's Theme (Best That You Can Do)Christopher Cross
1980Turning JapaneseThe Vapors
1971Power to the PeopleJohn Lennon
1962TelstarThe Tornados
2006HurtChristina Aguilera

Link to Bootstrap CSS and JS Files

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.min.js"></script>

Link to Bootstrap dataTables CSS and JS Files

<link href="https://cdn.datatables.net/1.12.1/css/jquery.dataTables.min.css" rel="stylesheet" type="text/css">
<script src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.min.js"></script>

PHP

<?php
  $conn = new mysqli ("server", "username", "password", "database-name");
  mysqli_set_charset ($conn, "utf8"); 
  
  $sql = "SELECT * FROM top_5000_songs ORDER BY RAND() LIMIT 0, 60";
  $result = $conn -> query($sql);
  
  echo "<table id=\"table-demo\" class=\"table table-striped\">";
  echo "<thead>";
  echo "<tr>";
  echo "<th>Year</th>";
  echo "<th>Song Title</th>";
  echo "<th>Artist</th>";
  echo "</tr>";
  echo "</thead>";
  echo "<tbody>"; 
  while ($row = $result -> fetch_assoc()) { 

  echo "<tr>";
  echo "<td>" . $row["year"] . "</td>";
  echo "<td>" . $row["song"] . "</td>";
  echo "<td>" . $row["artist"] . "</td>";
  }
  
  echo "</tr>";
  echo "</tbody>";
  echo "</table>";
  $conn -> close();
  ?>

JS

<script>
$(document).ready(function() {
$("#table-demo").DataTable({
paging: true,
pageLength: 4,
ordering: true,
info: false,
lengthChange: false,
language: {
search: "_INPUT_",
searchPlaceholder: "Search"
},
search: {
addClass: 'form-control input-lg col-xs-12',
},
});
});
</script>
   Display table records in a Bootstrap table