// define the SQL query to run (from lab 3 queries.sql!)
// use column aliases if necessary to make referencing fields in result-set easier
$sql="SELECT Album.title, Album.price, Album.upc, Artist.first_name, Artist.last_name, Genre.name AS genre, (SELECT COUNT(*) FROM Track WHERE Album.upc=Track.album_upc) AS num_tracks
FROM Album
INNER JOIN Artist
ON Album.artist_id=Artist.id
INNER JOIN Genre
ON Album.genre_id=Genre.id
ORDER BY title ASC;";
// query the database
$result=mysqli_query($link,$sql);
// update HTML content string with page title
$content.="<h1>Albums</h1>";
// get number of rows in result-set
$row_cnt=mysqli_num_rows($result);
// check if there are rows to display...
if($row_cnt==0){
// if not, output a suitable message
$content.="<p>There are no albums in the databased!</p>";
}else{
// otherwise, update the HTML in $content
$content.="<table cellpadding='4' border='1'>
<thead align='left'>
<tr>
<th>Album name</th>
<th>Artist name</th>
<th>Price</th>
<th>Genre</th>
<th>Number of tracks</th>
</tr>
</thead>
<tbody>";
// while there are rows, fetch each row as an associative array
while($row=mysqli_fetch_assoc($result)){
// append the content with more HTML containing row data