Database Code

  Home arrow Database Code arrow Dump a database to HTML tables
DATABASE CODE

Dump a database to HTML tables
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2002-01-18

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement
    Shows contents of a database in HTML.

    By : Tudor Oprea

    <?php
    //
    // PHPdbView 0.2 : 05-06-2000
    // Written by Tudor Oprea (tudor@interchange.ubc.ca)
    // Shows contents of a database in HTML.
    // To show another database, change first four variables.
    //
    //
    ?>

    <?php

    $dbname = "test";
    $loginname = "user";
    $loginpass = "password";
    $dbhost = "localhost";

    echo('<html><body bgcolor="#FFFFFF">');
    echo('<font face="arial" size="+4"><center>');
    echo("Database $dbname");

    $id_link = @mysql_connect($dbhost, $loginname, $loginpass);

    $tables = mysql_list_tables($dbname, $id_link);

    $num_tables = mysql_num_rows($tables);

    // store table names in an array
    $arr_tablenames[] = '';

    // store number of fields per table(index 0,1,2..) in an array
    $arr_num_fields[] = '';
    for ($i=0; $i < $num_tables; $i++) {
    $arr_tablenames[$i] = mysql_tablename($tables, $i);
    $arr_num_fields[$i] = mysql_num_fields(mysql_db_query($dbname, "select * from $arr_tablenames[$i]", $id_link));
    }

    // store field names in a multidimensional array:
    // [i] == table number, [ii] == field number for that table
    for ($i=0; $i < $num_tables; $i++) {
    for ($ii=0; $ii < $arr_num_fields[$i]; $ii++) {
    $result = mysql_db_query($dbname, "select * from $arr_tablenames[$i]", $id_link);
    $hash_field_names[$i][$ii] = mysql_field_name($result, $ii);
    }
    }

    for ($i=0; $i < $num_tables; $i++) {
    echo("<center><h2>Table $arr_tablenames[$i] </h2></center>");
    echo('<table align="center" border="1"><tr>');
    $result = mysql_db_query($dbname, "select * from $arr_tablenames[$i]", $id_link);
    for ($ii=0; $ii < $arr_num_fields[$i]; $ii++) {
    echo("<th>");
    echo $hash_field_names[$i][$ii];
    echo("</th>");
    }
    echo("</tr><tr>");
    $number_of_rows = @mysql_num_rows($result);
    for ($iii = 0; $iii < $number_of_rows; $iii++) {
    $record = @mysql_fetch_row($result);
    for ($ii=0; $ii < $arr_num_fields[$i]; $ii++) {
    echo("<td>");
    echo $record[$ii];
    echo("</td>");
    }
    echo("</tr>");
    }
    echo("</table>");
    }



    echo('</body></html>');
    ?>
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Database Code Articles
    More By Codewalkers

    blog comments powered by Disqus

    DATABASE CODE ARTICLES

    - Converting CSV Files to MySQL Insert Queries...
    - Examples and Tools for Database Design
    - Relationships, Entities and Database Design
    - Modeling and Designing Databases
    - Data extract to Excel
    - Oracle database class 0.76
    - The opposite of mysql_fetch_assoc
    - On line Thermal Transmitance Calculation
    - pjjTextBase
    - PHP Object Generator
    - FastMySQL
    - RC4PHP
    - SQL function with integrated sprintf()
    - DB Interaction Classes v1.1
    - deeMySQLParser


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap