Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. <?php
  2. $db_host = 'localhost'; // Server Name
  3. $db_user = 'root'; // Username
  4. $db_pass = ''; // Password
  5. $db_name = 'songs'; // Database Name
  6.  
  7. $conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
  8. if (!$conn) {
  9. die ('Failed to connect to MySQL: ' . mysqli_connect_error());
  10. }
  11.  
  12. if (isset($_POST['keyword'])) {
  13. // Filter
  14. $keyword = trim ($_POST['keyword']);
  15.  
  16. // Select statement
  17. $sql = "SELECT * FROM songs WHERE name LIKE '%$keyword%'";
  18. } else {
  19. $sql = 'SELECT *
  20. FROM songs';
  21. }
  22.  
  23. $query = mysqli_query($conn, $sql);
  24.  
  25. if (!$query) {
  26. die ('SQL Error: ' . mysqli_error($conn));
  27. }
  28. ?>
  29. <html>
  30. <head>
  31. <title>Listening History</title>
  32. <style type="text/css">
  33. body {
  34. font-size: 15px;
  35. color: #343d44;
  36. font-family: "segoe-ui", "open-sans", tahoma, arial;
  37. padding: 0;
  38. margin: 0;
  39. }
  40.  
  41. /* Search */
  42. input[type=button], input[type=submit], input[type=reset] {
  43. background-color: #508abb;
  44. font-family: "Lucida Sans Unicode", "Lucida Grande", "Segoe Ui";
  45. font-size: 16px;
  46. border: none;
  47. color: white;
  48. padding: 10px 22px;
  49. text-decoration: none;
  50. margin: 4px 2px;
  51. cursor: pointer;
  52. }
  53.  
  54. input[type=text] {
  55. background-color: #508abb;
  56. color: white;
  57. font-family: "Lucida Sans Unicode", "Lucida Grande", "Segoe Ui";
  58. font-size: 16px;
  59. background-position: 10px 10px;
  60. background-repeat: no-repeat;
  61. }
  62.  
  63. table {
  64. margin: auto;
  65. font-family: "Lucida Sans Unicode", "Lucida Grande", "Segoe Ui";
  66. font-size: 12px;
  67. }
  68.  
  69. h1 {
  70. margin: 25px auto 0;
  71. text-align: center;
  72. text-transform: uppercase;
  73. font-size: 17px;
  74. }
  75.  
  76. table td {
  77. transition: all .5s;
  78. }
  79.  
  80. /* Table */
  81. .data-table {
  82. border-collapse: collapse;
  83. font-size: 14px;
  84. min-width: 537px;
  85. }
  86.  
  87. .data-table th,
  88. .data-table td {
  89. border: 1px solid #e1edff;
  90. padding: 7px 17px;
  91. }
  92. .data-table caption {
  93. margin: 7px;
  94. }
  95.  
  96. /* Table Header */
  97. .data-table thead th {
  98. background-color: #508abb;
  99. color: #FFFFFF;
  100. border-color: #6ea1cc !important;
  101. text-transform: uppercase;
  102. }
  103.  
  104. /* Table Body */
  105. .data-table tbody td {
  106. color: #353535;
  107. }
  108. .data-table tbody td:first-child,
  109. .data-table tbody td:nth-child(4),
  110. .data-table tbody td:last-child {
  111. text-align: right;
  112. }
  113.  
  114. .data-table tbody tr:nth-child(odd) td {
  115. background-color: #f4fbff;
  116. }
  117. .data-table tbody tr:hover td {
  118. background-color: #ffffa2;
  119. border-color: #ffff0f;
  120. }
  121.  
  122. /* Table Footer */
  123. .data-table tfoot th {
  124. background-color: #e5f5ff;
  125. text-align: right;
  126. }
  127. .data-table tfoot th:first-child {
  128. text-align: left;
  129. }
  130. .data-table tbody td:empty
  131. {
  132. background-color: #ffcccc;
  133. }
  134. </style>
  135. </head>
  136. <body>
  137. <h1>Songs</h1>
  138. <table class="data-table">
  139. <caption class="title">Song Listening History</caption>
  140. <thead>
  141. <center>
  142. <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
  143. <input type="text" name="keyword">
  144. <input type="submit" name="search" value="Search">
  145. </center>
  146. <tr>
  147. <th>ID</th>
  148. <th>NAME</th>
  149. <th>ARTIST</th>
  150. <th>ALBUM</th>
  151. <th>DURATION</th>
  152. </tr>
  153. </thead>
  154. <tbody>
  155. <?php
  156. $id = 1;
  157. $total = 0;
  158. while ($row = mysqli_fetch_array($query))
  159. {
  160. $duration = $row['duration'] == 0 ? '' : number_format($row['duration']);
  161. echo '<tr>
  162. <td>'.$id.'</td>
  163. <td>'.$row['name'].'</td>
  164. <td>'.$row['artist'].'</td>
  165. <td>'.$row['album'].'</td>
  166. <td>'.$row['duration'].'</td>
  167. </tr>';
  168. $id++;
  169. }
  170. ?>
  171. </tbody>
  172. </table>
  173. </body>
  174. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement