Logo Luan Morina
Display MySQL table records in a Bootstrap table
YearSong TitleArtist
2010The Only ExceptionParamore
1973Gudbye T'JaneSlade
1973Touch Me in the MorningDiana Ross
1970Long As I Can See the LightCreedence Clearwater Revival
1947Blue Moon of KentuckyBill Monroe
2004Somewhere Only We KnowKeane
1975Pick Up the PiecesAverage White Band
1983JulietRobin Gibb
1984HolidayMadonna
1996FirestarterThe Prodigy
1980Cruisin'Smokey Robinson
1975Bye Bye BabyThe Bay City Rollers
1966DaydreamLovin' Spoonful
1985Freeway of LoveAretha Franklin
1972Brandy (You're A Fine Girl)Looking Glass
1989Angel of HarlemU2
1972Morning Has BrokenCat Stevens
1940You Are My SunshineJimmie Davis
2004My PerogativeBritney Spears
1968Cinderella RockefellaEsther & Abi Ofarim
2007Do You Know (The Ping Pong Song)Enrique Iglesias
1920Crazy BluesMamie Smith
1978Every 1's a WinnerHot Chocolate
1992Friday, I'm in LoveThe Cure
1962(I Left My Heart in) San FranciscoTony Bennett
1963The Next TimeCliff Richard
2013Thrift ShopMacklemore & Ryan Lewis
1996Hey LoverLL Cool J
1946Ole Buttermilk SkyKay Kyser
1963The End of the WorldSkeeter Davis
2012Somebody That I Used to KnowGotye & Kimbra
1955Learnin' the BluesFrank Sinatra
2000Gotta Tell YouSamantha Mumba
1985I Got You BabeUB40 & Chrissie Hynde
1962Soldier BoyThe Shirelles
1992Baby, Baby, BabyTLC
1979TragedyBee Gees
1979In the NavyThe Village People
1993The Crying GameBoy George
1974Never Never Gonna Give Ya UpBarry White
1993If I Had No LootTony! Toni! Tone!
1993Cryin'Aerosmith
1939Over the RainbowJudy Garland
1994Move On BabyCappella
1995Ode to My FamilyThe Cranberries
1972Crazy HorsesThe Osmonds
1996How BizarreOMC
1976Rock 'n' MeSteve Miller Band
1985Material GirlMadonna
2001Hey Baby (Uuh, Aah)DJ Otzi
1984Love of the Common PeoplePaul Young
1968Bend Me Shape MeAmerican Breed
1998This KissFaith Hill
1980The RoseBette Midler
1968Dance to the MusicSly & The Family Stone
1979One Way TicketEruption
2004TipsyJ-Kwon
1988You CameKim Wilde
1972Summer BreezeSeals & Crofts
2000StanEminem

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