Advertisement
Guest User

Untitled

a guest
Aug 7th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.79 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 = "LVDM";
  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>";
  42.             echo "</tr>";  
  43.             foreach ($categories as $cat) {
  44.                 echo "<th>".$cat."</th>";
  45.             }
  46.                
  47.             $result = $conn->query($sql);
  48.            
  49.             if ($result->num_rows > 0) {
  50.                 while ($row = $result->fetch_assoc()){
  51.                     foreach ($row as $index=>$value) {
  52.                         if ($index !== "id") {
  53.                             echo "<tr>";
  54.                         }
  55.                         $id;
  56.                         $usr;
  57.                         if ($index == "id")
  58.                             $id = $value;
  59.                         if ($index == "username")
  60.                             $usr = $value;
  61.  
  62.                         if ($index ==  $cat) {
  63.                             echo "<td>$id</td>";
  64.                             echo "<td>$usr</td>";
  65.                         }
  66.                         echo "</tr>";
  67.                     }
  68.                 }
  69.             }
  70.             else {
  71.                 echo "0 result";
  72.             }
  73.         }  
  74.         $conn->close();
  75.     echo "</table>";  
  76.     ?>
  77. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement