Advertisement
Guest User

Untitled

a guest
Aug 30th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. <?php
  2. $db_host = 'localhost'; // Server Name
  3. $db_user = 'root'; // Username
  4. $db_pass = ''; // Password
  5. $db_name = 'tutorial'; // 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. $sql = 'SELECT * FROM votesGALTotals ORDER BY votes,username DESC LIMIT ';
  13.  
  14. $query = mysqli_query($conn, $sql);
  15.  
  16. if (!$query) {
  17. die ('SQL Error: ' . mysqli_error($conn));
  18. }
  19. ?>
  20. <html>
  21. <head>
  22. <title>Voting Page</title>
  23. <style type="text/css">
  24. body {
  25. font-size: 15px;
  26. color: #343d44;
  27. font-family: "segoe-ui", "open-sans", tahoma, arial;
  28. padding: 0;
  29. margin: 0;
  30. }
  31. table {
  32. margin: auto;
  33. font-family: "Lucida Sans Unicode", "Lucida Grande", "Segoe Ui";
  34. font-size: 12px;
  35. }
  36.  
  37. h1 {
  38. margin: 25px auto 0;
  39. text-align: center;
  40. text-transform: uppercase;
  41. font-size: 17px;
  42. }
  43.  
  44. table td {
  45. transition: all .5s;
  46. }
  47.  
  48. /* Table */
  49. .data-table {
  50. border-collapse: collapse;
  51. font-size: 14px;
  52. min-width: 537px;
  53. }
  54.  
  55. .data-table th,
  56. .data-table td {
  57. border: 1px solid #e1edff;
  58. padding: 7px 17px;
  59. }
  60. .data-table caption {
  61. margin: 7px;
  62. }
  63.  
  64. /* Table Header */
  65. .data-table thead th {
  66. background-color: #508abb;
  67. color: #FFFFFF;
  68. border-color: #6ea1cc !important;
  69. text-transform: uppercase;
  70. }
  71.  
  72. /* Table Body */
  73. .data-table tbody td {
  74. color: #353535;
  75. }
  76. .data-table tbody td:first-child,
  77. .data-table tbody td:nth-child(4),
  78. .data-table tbody td:last-child {
  79. text-align: right;
  80. }
  81.  
  82. .data-table tbody tr:nth-child(odd) td {
  83. background-color: #f4fbff;
  84. }
  85. .data-table tbody tr:hover td {
  86. background-color: #ffffa2;
  87. border-color: #ffff0f;
  88. }
  89.  
  90. /* Table Footer */
  91. .data-table tfoot th {
  92. background-color: #e5f5ff;
  93. text-align: right;
  94. }
  95. .data-table tfoot th:first-child {
  96. text-align: left;
  97. }
  98. .data-table tbody td:empty
  99. {
  100. background-color: #ffcccc;
  101. }
  102. </style>
  103. </head>
  104. <body>
  105. <h1>Top Voters</h1>
  106. <table class="data-table">
  107. <caption class="title">Top Voters</caption>
  108. <thead>
  109. <tr>
  110. <th>Username</th>
  111. <th>Votes</th>
  112. </tr>
  113. </thead>
  114. <tbody>
  115. <?php
  116. $no = 1;
  117. $total = 0;
  118. while ($row = mysqli_fetch_array($query))
  119. {
  120. $amount = $row['amount'] == 0 ? '' : number_format($row['amount']);
  121. echo '<tr>
  122. <td>'.$no.'</td>
  123. <td>'.$row['name'].'</td>
  124. <td>'.$row['Votes'].'</td>
  125. }?>
  126. </tbody>
  127. <tfoot>
  128. <tr>
  129. <th colspan="4">TOTAL</th>
  130. <th><?=number_format($total)?></th>
  131. </tr>
  132. </tfoot>
  133. </table>
  134. </body>
  135. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement