-
Notifications
You must be signed in to change notification settings - Fork 0
/
albumList.php
99 lines (75 loc) · 2.63 KB
/
albumList.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<doctype! html>
<html>
<head>
<title> Album </title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/mgalante/jquery.redirect/master/jquery.redirect.js"></script>
<script>
function insPlay(id) {
$.post('insertPlay.php', {'id':id});
alert("Playing!");
}
</script>
</head>
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "";
function displayInfo($id) {
global $servername, $username, $password;
$mysqli = new mysqli($servername, $username, $password, "dbproject");
if (mysqli_connect_errno()) {
die("Connect to db failed: " . "<br>" . mysqli_connect_error() );
}
$statement = "SELECT albtitle, albid FROM Album WHERE albid = " . $id . "";
$stmt = $mysqli->prepare($statement);
$stmt->execute();
$stmt->bind_result($title, $alid);
$valid = $stmt->fetch();
$stmt->close();
echo "<h1> {$title} Track List </h1>";
$statement = "SELECT Track.ttitle, Track.trackID, Track.tduration, Artist.aname from ((Album join TrackList on Album.albid = TrackList.albid) join Track on TrackList.trackID = Track.trackID) join Artist on Track.aid = Artist.aid where Album.albid = {$id}";
$stmt = $mysqli->prepare($statement);
$stmt->execute();
$stmt->bind_result($title, $tid, $dur, $name);
$valid = $stmt->fetch();
echo "<table border=\"1\">";
echo "<tr><td> <div style = \"background-color:#333333; color:#FFFFFF; padding:3px;\" align=\"center\"><b>Track Name</b></div> </td>";
echo "<td> <div style = \"background-color:#333333; color:#FFFFFF; padding:3px;\" align=\"center\"><b>Artist</b></div> </td>";
echo "<td> <div style = \"background-color:#333333; color:#FFFFFF; padding:3px;\" align=\"center\"><b>Duration</b></div> </td>";
echo "<td> <div style = \"background-color:#333333; color:#FFFFFF; padding:3px;\" align=\"center\"><b>Play</b></div> </td>";
while($valid) {
$minutes = floor($dur/60);
$seconds = $dur%60;
echo "<tr>";
echo "<td>";
echo $title;
echo "</td>";
echo "<td>";
echo $name;
echo "</td>";
echo "<td>";
echo $minutes . "m " . $seconds . "s";
echo "</td>";
echo "<td>";
echo "<button onclick=\"insPlay({$id})\"><u>Play</u></button>";
echo "</tr>";
echo "</td>";
$valid = $stmt->fetch();
}
echo "</table><br>";
echo "<form action=\"welcome.php\" method=\"post\">";
echo "<input type=\"submit\" class=\"button\" value=\"Home\">";
echo "</form>";
$stmt->close();
$mysqli->close();
}
?>
<?php
session_start();
$id = $_POST['id'];
displayInfo($id);
?>
</body>
</html>