PageRenderTime 48ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/music.php

https://bitbucket.org/wlynch92/cs336-dbproject
PHP | 70 lines | 54 code | 15 blank | 1 comment | 8 complexity | b8945dfb5f7306a81efffb412d302b09 MD5 | raw file
  1. <html>
  2. <head><title>Top Songs & Artists </title></head>
  3. <body>
  4. <a href="/profile.php"><h1>Music Box</h1></a>
  5. A social music site for everyone!<p>
  6. <?php
  7. session_start();
  8. if($_SESSION['username']){
  9. #echo "<br>";
  10. echo "<div align = \"left\"> <a href=\"/logout.php\">Logout</a><br></div>";
  11. }
  12. if ($_SESSION['username']){
  13. echo "Logged in as: ".$_SESSION['username']."\n<p>\n";
  14. }
  15. ?>
  16. <div align=right>
  17. | <a href="/music.php">Top Songs & Artists</a> |
  18. <a href="/artistfind.php">Search for Artist</a> |
  19. <a href="/random.php">Site Info and Facts</a> |
  20. </div>
  21. <p><center><hr width=100% noshade=noshade></center><p>
  22. <form action="/artistfind.php" method="post">
  23. Search for artist: <input type="text" name="artist">
  24. <input type="submit" value="Search">
  25. </form>
  26. <?php
  27. session_start();
  28. $con = mysql_connect("cs336-64.rutgers.edu", "csuser", "cs277315");
  29. if (!$con) {
  30. die('cannot connect: '.mysql_error());
  31. }
  32. mysql_select_db("cs336", $con);
  33. $topSongs = mysql_query("select s.sname, count(*) as count from likesSong l, song s where s.sid = l.sid group by l.sid order by count DESC");
  34. $topArtists = mysql_query("select a.name, count(*) as count from likesArtist l, artist a where a.aid = l.aid group by l.aid order by count DESC");
  35. echo "<center><h2>The Popularity Chart</h2></center>";
  36. echo "<p><b>Top 10 Songs</b><ul>";
  37. $counter = 0;
  38. while ($topSongsTable = mysql_fetch_array($topSongs) AND $counter < 10) {
  39. echo "<li>\"".$topSongsTable['sname']."\" -- <b>Likes: </b>";
  40. echo $topSongsTable['count']."</li>";
  41. $counter = $counter + 1;
  42. }
  43. echo "</ul>";
  44. echo "<p><b>Top 5 Artists</b><ul>";
  45. $counter = 0;
  46. while ($topArtistTable = mysql_fetch_array($topArtists) AND $counter < 5) {
  47. echo "<li>".$topArtistTable['name']." -- <b>Likes: </b>";
  48. echo $topArtistTable['count']."</li>";
  49. $counter = $counter + 1;
  50. }
  51. echo "</ul>";
  52. mysql_close($con);
  53. ?>
  54. </body>
  55. </html>