topical media & game development
[] readme course(s) preface I 1 2 II 3 4 III 5 6 7 IV 8 9 10 V 11 12 afterthought(s) appendix reference(s) example(s) resource(s) _

talk show tell print

portal-xml-getdb.php



  <?php
  
  if(_GET['table']){
      header ("content-type: text/xml");
  } else {
      print('
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
      <head>
          <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
          <title>XML Database Parser</title>
          <link href="style.css" rel="stylesheet" type="text/css" />
      </head>
      <body>
      <h1>XML Database Parser</h1>
  <div style="float: right;">
  <iframe name="goalWin"></iframe>
  </div>
      ');
  }
  
  mysql_connect("tornado","mwg400","48458749") or die ("Kan niet connecten.");
  tabellen = mysql_list_tables( "mwg400-dbs");
  
  mysql_select_db("mwg400-dbs") or die ("Verdorie, kan de database 
  niet openen");
  
  if(_GET['table']){
      date = date("d-m-Y, H:i:s",now);
      now = mktime();
      echo '<?xml version="1.0" encoding="iso-8859-1" ?>';
   /*   
      echo '<?xml-stylesheet type="text/xsl" href="style.xsl"?>';
  */
      echo "<document>
      <author>S. Bankras</author>
      <date>".date."</date>
      <table>"._GET['table']."</table>
      <description></description>
      ";
      result = mysql_query("SELECT * FROM "._GET['table']);
      while (row = mysql_fetch_array (result)) {
          echo "<item>\n";
          foreach(row as key => value){
              if(!is_int(key)){
                  value = strip(value);
                  if(value){
                      echo "<".key.">".value."</".key.">\n";
                  }
              }
          }
          echo "</item>\n";
      }
      print("</document>\n");
  } else {
  
      /*
      Tellertje en loop om de tabellen te tonen.
      */
      echo "<fieldset><legend><b>List of all tables in the database</b></legend>";
      i=0;
      while (i < mysql_num_rows(tabellen)){
          t_name[i] = mysql_tablename (tabellen, i);
          echo "<a target='goalWin' href='getdb.php?table=".t_name[i]. "'>".t_name[i]."</a><br />\n";
          i++;
      }   
      echo "</fieldset>";
      mysql_free_result (result);
  }
  
  if(!_GET['table']){
  ?>
  <hr />
  Created for MMC2007
  <div>
    <img
          src="http://www.w3.org/Icons/valid-xhtml10"
          alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a>
          </div>
  </body>
  </html>
  <?php 
  } 
  
  function strip(text){
      text = str_replace("&ndash;", "&#45;",text);
      text = str_replace("&acirc;", "NULL",text);
      text = str_replace("&Acirc;", "NULL",text);
      text = htmlentities(text);
      return text;
  }
  
  ?>


(C) A. Eliëns 2/9/2007

You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.