<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
		"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>MySQL-Anwendung über mehrere Seiten</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<!--
//    This file is part of a php tutorial
//
//    (C) Copyright 2009 Hans Kern
//
//    Created by   : Hans Kern
//    Creation date: 09.03.2010
-->
<?php
require_once("dbConnect.inc.php");

echo "<p>Aktionen - Tabellen - Anzeigen</p>\n";
echo "<form method='get' action=''>\n";
if (!array_key_exists('step3',$_GET)) {
   if (!array_key_exists('step2',$_GET)) {
      // We are now in step1
      echo "<p>Bitte wählen Sie eine Datenbank!</p>\n";
      echo "<p>";
      $sql = "SHOW DATABASES";
      $sth = mysql_query($sql) OR die('Mist! '. mysql_error());

      echo "<select name='step2' size='1'>\n";
      echo "<option>Datenbank wählen</option>\n";
      while ($row = mysql_fetch_row($sth)) {
         echo "<option>$row[0]</option>\n";
      }
      mysql_free_result($sth);
      echo "</select>\n";
      echo "</p>\n";
      echo "<p>\n";
      echo "<input type='submit' name='anzeigen' value='Weiter' />\n";
      echo "<input type='reset' name='loeschen' value='Zurück' />\n";
      echo "</p>\n";
   } else {
      // We are now in step2
      $step2 = $_GET['step2'];
      echo "<p>Bitte wählen Sie eine Tabelle in der Datenbank <b>$step2</b>!</p>\n";
      echo "<p>";
      $sql = "USE $step2";
      $sth = mysql_query($sql) OR die('Mist! '. mysql_error());
      $sql = "SHOW TABLES";
      $sth = mysql_query($sql) OR die('Mist! '. mysql_error());

      echo "<select name='tab' size='1'>\n";
      echo "<option>Tabelle wählen</option>\n";
      while ($row = mysql_fetch_row($sth)) {
        echo "<option>$row[0]</option>\n";
      }
      mysql_free_result($sth);
      echo "</select>\n";
      echo "</p>\n";
      echo "<p>\n";
      echo "<input type='hidden' name='step3' value='$step2' />\n";
      echo "<input type='submit' name='anzeigen' value='Weiter' />\n";
      echo "<input type='reset' name='loeschen' value='Zurück' />\n";
      echo "</p>\n";
   }
} else {
   // We are now in step3
   $step3 = $_GET['step3'];
   if (array_key_exists('tab',$_GET)) {
     $tab = $_GET['tab'];
   }
   echo "<p>Sie haben die Tabelle <b>$tab</b> in der Datenbank <b>$step3</b> gewählt!</p>\n";
   echo "<p>";
   $sql = "SELECT * FROM $step3.$tab";
   $sth = mysql_query($sql) OR die('Mist! '. mysql_error());

   for ($i = 0; $i < mysql_num_fields($sth); $i++) {
      $col = mysql_field_name($sth,$i);
      echo "$col &nbsp;|&nbsp; ";
   }
   echo "<br />\n";

   while ($ar = mysql_fetch_row($sth)) {
      foreach ($ar as $col) {
         echo htmlentities($col,ENT_QUOTES,'UTF-8')." &nbsp;|&nbsp; ";
      }
      echo "<br />\n ";
      echo "\n";
   }
   mysql_free_result($sth);
   echo "</p>\n";
   echo "<p>\n";
   echo "<input type='submit' name='anzeigen' value='Weiter' />\n";
   echo "<input type='reset' name='loeschen' value='Zurück' />\n";
   echo "</p>\n";
}
echo "</form>\n";
echo "<p><a href='mysql_all.php'>Weiter?</a></p>\n";
?>
</body>
</html>
