Rafsys

Untitled

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