| Name | GenreID | Composer | UnitPrice | |
|---|---|---|---|---|
| For Those About To Rock (We Salute You) | 1 | Angus Young, Malcolm Young, Brian Johnson | 0.99 | |
| Balls to the Wall | 1 | U. Dirkschneider, W. Hoffmann, H. Frank, P. Baltes, S. Kaufmann, G. Hoffmann | 0.99 | |
| Fast As a Shark | 1 | F. Baltes, S. Kaufman, U. Dirkscneider & W. Hoffman | 0.99 | |
| Restless and Wild | 1 | F. Baltes, R.A. Smith-Diesel, S. Kaufman, U. Dirkscneider & W. Hoffman | 0.99 | |
| Princess of the Dawn | 1 | Deaffy & R.A. Smith-Diesel | 0.99 | |
| Put The Finger On You | 1 | Angus Young, Malcolm Young, Brian Johnson | 0.99 | |
| Let's Get It Up | 1 | Angus Young, Malcolm Young, Brian Johnson | 0.99 | |
| Inject The Venom | 1 | Angus Young, Malcolm Young, Brian Johnson | 0.99 | |
| Snowballed | 1 | Angus Young, Malcolm Young, Brian Johnson | 0.99 | |
| Evil Walks | 1 | Angus Young, Malcolm Young, Brian Johnson | 0.99 | |
| C.O.D. | 1 | Angus Young, Malcolm Young, Brian Johnson | 0.99 | |
| Breaking The Rules | 1 | Angus Young, Malcolm Young, Brian Johnson | 0.99 | |
| Night Of The Long Knives | 1 | Angus Young, Malcolm Young, Brian Johnson | 0.99 | |
| Spellbound | 1 | Angus Young, Malcolm Young, Brian Johnson | 0.99 | |
| Go Down | 1 | AC/DC | 0.99 | |
| Dog Eat Dog | 1 | AC/DC | 0.99 | |
| Let There Be Rock | 1 | AC/DC | 0.99 | |
| Bad Boy Boogie | 1 | AC/DC | 0.99 | |
| Problem Child | 1 | AC/DC | 0.99 | |
| Overdose | 1 | AC/DC | 0.99 |
<?php
$conn = createConn();
session_start();
if (isset($_GET['add'])){
$tracknum=$_GET['hiddenformid'];
if (isset($_SESSION['playlistcount'])){
$_SESSION['playlistcount']++;
$count = $_SESSION['playlistcount'];
}
else{
$_SESSION['playlistcount']=1;
$count= $_SESSION['playlistcount'];
}
$_SESSION['playlistarray'][$count]=$tracknum;
}
if (isset($_GET['delete'])){
$trackidfromform=$_GET['trackidtodelete'];
$linetodelete=$_GET['lineidtodelete'];
$count=$_SESSION['playlistcount'];
for ($i=1; $i<=$count; $i++){
if (isset($_SESSION['playlistarray'][$i])){
if ($linetodelete == $i){
$idselected = $_SESSION['playlistarray'][$i];
if ($idselected == $trackidfromform){
$deletedindex=$i;
unset($_SESSION['playlistarray'][$i]);
$_SESSION['playlistcount'] = $_SESSION['playlistcount']-1;
$count=$_SESSION['playlistcount'];
for ($x=$deletedindex; $x<=$count; $x++){
$_SESSION['playlistarray'][$x] = $_SESSION['playlistarray'][$x+1];
//after deleting an array item's contents, move each subsequent array item's contents down by one space
//do not move anything in the preceeding array elements.... only start with blank element +1
}//endfor elements between deleted item and total of count
}//endif id matches button
}//endif line matches counter
}//endif isset array element
}//endfor loop iterations = amount of $count
if ($count<=0){//don't print playlist header if session is unset
unset($_SESSION);
session_destroy();
}
}// end if isset delete
if (isset($_SESSION['playlistcount'])){
?>
<u><h2>Your Playlist</h2></u>
<table>
<tr><th>TrackName..</th><th>Composer..</th><th>Genre..</th><th></th></tr>
<?php
for ($i=1; $i<=$count; $i++){
if (isset($_SESSION['playlistarray'][$i])){
$line=$i;
$chosenid = ($_SESSION['playlistarray'][$i]);
$query = "Select Name, Composer, GenreId from Track where TrackId = $chosenid";
$result = mysqli_query($conn,$query);
if (!$result){
die(mysqli_error($conn));
}
if (mysqli_num_rows($result)> 0){
$row = mysqli_fetch_assoc($result);
echo "<tr><td>".$row['Name']."</td>";
echo "<td>".$row['Composer']."</td>";
echo "<td>".$row['GenreId']."</td>";
?>
<td><form method="get" action="php-tracks.php">
<input type='hidden' name='trackidtodelete' size="1" value="<?php echo $_SESSION['playlistarray'][$i]; ?>">
<input type='hidden' name='lineidtodelete' size="1" value="<?php echo $line; ?>">
<input type="submit" name="delete" value="remove"></form></td></tr>
<?php
}//end if sqli result
}//end if isset array
}//end forloop
}//end if isset playlist count
echo "</table>";
//////////////////////////////////////////////////PROCESS COOKIES
//if name cookie set, say welcome
if(isset($_COOKIE['name'])){echo "Welcome, " . $_COOKIE['name'] . "!";}
//if discount cookie set, say discount
if(isset($_COOKIE['coupon'])){echo " Order today to receive 25% off your entire order!";}
//if genre1 cookie set, fill $genre1 variable
//+ check for genre2 and genre3 cookies and fill vars if needed
//+ create query if genre cookies found
if(isset($_COOKIE['genre1']))
{
$genre1=$_COOKIE['genre1'];
$query = "select * from Track where GenreId = $genre1 Limit 20";
if(isset($_COOKIE['genre2']))
{$genre2=$_COOKIE['genre2'];
$query = "select * from Track where GenreId = $genre2 or GenreId = $genre1 Limit 20";}
if(isset($_COOKIE['genre3']))
{$genre3=$_COOKIE['genre3'];
$query = "select * from Track where GenreId = $genre1 or GenreId = $genre3 or GenreId = $genre2 Limit 20";}
}
else{
//if no genre cookie exists....
//NOTE to be here at all, you would have a NAME and at least ONE GENRE selected (unless direct via url)
$query = "select * from Track Limit 20";
};
?>
<u><h2>Tracks You May Like</h2></u>
<table>
<tr><th>Name</th><th>GenreID</th><th>Composer</th><th>UnitPrice</th><th></th></tr>
<?php
$result = mysqli_query($conn,$query);
if (!$result){
die(mysqli_error($conn));
}
if (mysqli_num_rows($result)> 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo "<tr><td>".$row['Name']."</td>";
echo "<td>".$row['GenreId']."</td>";
echo "<td>".$row['Composer']."</td>";
echo "<td>".$row['UnitPrice']."</td>";
?>
<td>
<form method='get' action='php-tracks.php'>
<input type='hidden' name='hiddenformid' value="<?php echo $row['TrackId']; ?>">
<input type='submit' name='add' value='Add to playlist'>
</form>
</td>
</tr>
<?php
}
}
?>