Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.41 KB | None | 0 0
  1. <html>
  2. <head>
  3. <style>
  4. table {
  5.     font-family: arial, sans-serif;
  6.     border-collapse: collapse;
  7.     width: 100%;
  8. }
  9.  
  10. td, th {
  11.     border: 1px solid #dddddd;
  12.     text-align: left;
  13.     padding: 8px;
  14. }
  15.  
  16. tr:nth-child(even) {
  17.     background-color: #dddddd;
  18. }
  19. </style>
  20. </head>
  21. <body>
  22.  
  23.     <?php
  24.         echo "<table style='width:100%'>";
  25.         $servername = "localhost";
  26.         $username = "****";
  27.         $password = "****";
  28.         $db = "Ragnarok";
  29.         $tables = array ("userinfo");
  30.         $categories = array ("id", "username");
  31.        
  32.         // Create connection
  33.         $conn = new mysqli($servername, $username, $password, $db);
  34.  
  35.         // Check connection
  36.         if ($conn->connect_error) {
  37.             die("Connection failed: " . $conn->connect_error);
  38.         }
  39.         foreach ($tables as $tbl ) {
  40.             $sql = "SELECT id, username, password, serial FROM ". $tbl;
  41.             echo "<tr><th>". $tbl. "</th></tr>";
  42.             echo "<tr>";
  43.             foreach ($categories as $cat) {
  44.                 echo "<th>".$cat."</th>";
  45.             }  
  46.             echo "</tr>";  
  47.                
  48.             $result = $conn->query($sql);
  49.            
  50.             if ($result->num_rows > 0) {
  51.                 while ($row = $result->fetch_assoc()){
  52.                     foreach ($row as $index=>$value) {
  53.                         foreach ($categories as $cat) {
  54.                             if ($index !== "id") {
  55.                                 echo "<tr>";
  56.                             }
  57.                             if ($index ==  $cat) {
  58.                                 echo "<td>$value</td>";
  59.                             }  
  60.                         }  
  61.                     }
  62.                 }
  63.             }
  64.             else {
  65.                 echo "0 result";
  66.             }
  67.         }  
  68.         $conn->close();
  69.     echo "</table>";   
  70.     ?>
  71. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement