<html>
<head>
<title></title>
</head>
<body>

<h2>Show Tables</h2>
<p>
<a href='showtable.php?table=macaddrs'>macaddrs</a> 
<a href='showtable.php?table=sessionmd'>sessionmd</a> 
<a href='showtable.php?table=sessionview'>sessionview</a> 
<a href='showtable.php?table=nicvendors'>nicvendors</a> <br>
(Show max 1000 rows of selected table).
</p>

<?php
  /************************************************************/
  // show last 1000 rows of selected database on the web page.
  // the database connection parameters might be modified.
  // As this script should be used only by the administrators, 
  // it should be protected by some access control method.
  /************************************************************/

  // no table is indicated 
  if(!isset($_GET['table']))return;

  // connect and access to MySql DB
  $link = mysqli_connect('localhost', 'root', '');
  if (!$link) die('Cannot connect DB'.mysqli_error());
   
  $db_selected = mysqli_select_db($link, 'opengatem');
  if (!$db_selected) die('Cannot select DB'.mysqli_error());
   
  mysqli_set_charset($link, 'utf8');
   
  $result = mysqli_query($link, 'SELECT * FROM '.$_GET['table'].' limit 1000');
  if (!$result) die('Fail query'.mysqli_error());
   
  // print header
  print("<table border=1>");
  print('<tr>');
  $count=0;
  while ($field = mysqli_fetch_field($result)) {
    print('<td>'.$field->name.'</td>');
    $count++;
  }
  print('</tr>');

  // print rows
  while ($row = mysqli_fetch_row($result)) {
    print('<tr>');
    for($i=0; $i<$count; $i++){
      print('<td>'.$row[$i].'</td>');
    }
    print('</tr>');
  }
  print("</table>");
  $close_flag = mysqli_close($link);

?>

</body>
</html>
