<?php

include("config.php");

echo "<style>";
echo "TABLE { border-collapse:collapse;border:1px solid gray; } TD {border:1px solid gray}";
echo "</style>";

$results = mysqli_query($base, "SHOW TABLES");
if($results == false)   die("Empty database");

$tables = array();
while($arr = mysqli_fetch_array($results))
{
  array_push($tables, $arr['0']);
}

echo "<h2>Database structure : ".DB_NAME."</h2>";

foreach($tables as $table)
{
  $results = mysqli_query($base, "DESCRIBE $table");
  
  echo "<h3>TABLE $table</h3>\n";

  echo "<table>";
  echo "<tr><td>Name</td>\n";
  while($arr = mysqli_fetch_array($results))
  {
    echo "<td style='padding:4px'> ".$arr['0']."</td>";
  }
  mysqli_data_seek($results, 0);
  echo "</tr>\n"; 
  echo "<tr><td>Type</td>\n";

  while($arr = mysqli_fetch_array($results))
  {
    echo "<td> ".$arr['1']."</td>";
  }
  mysql_data_seek($results, 0);
  echo "</tr>\n"; 
  echo "<tr><td>May be NULL</td>\n";
  while($arr = mysqli_fetch_array($results))
  {
    echo "<td> ".$arr['2']."</td>";
  }
  mysqli_data_seek($results, 0);
  echo "</tr>\n"; 
  echo "<tr><td>PRIMARY KEY</td>\n";
  while($arr = mysqli_fetch_array($results))
  {
    echo "<td> ".$arr['3']."</td>";
  }    
  echo "</tr>\n"; 
  echo "</table>";
}

  echo "<br>Scriptol.fr";

?>