Database Articles

  Home arrow Database Articles arrow Create a Table Using Oracle HTML Table
DATABASE ARTICLES

Create a Table Using Oracle HTML Table
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2011-02-02

    Table of Contents:
  • Create a Table Using Oracle HTML Table
  • Creating More Readable Row Output

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Create a Table Using Oracle HTML Table


    (Page 1 of 2 )

    In this second part of a five-part series on using Oracle's HTML Table with advanced queries, you'll learn how to create a simple table and more. This article is excerpted from chapter 34 of the book Beginning PHP and Oracle: From Novice to Professional, written by W. Jason Gilmore and Bob Bryla (Apress; ISBN: 1590597702).

    Creating a Simple Table

    At its most basic level, HTML_Table requires just a few commands to create a table. For instance, suppose you want to display an array of employee data as an HTML table. Listing 34-1 offers an introductory example that contains a simple CSS style sheet in conjunction withHTML_TABLEto format the employee data found in the$empl_reportarray.

    Listing 34-1. Formatting Employee Data with HTML_Table (html_table_no_db.php)

    <style>

    table {
          border-width: 1px 1px 1px 1px;
          border-spacing: 2px;
          border-style: outset outset outset outset;
          border-color: gray gray gray gray;
          border-collapse: separate;
          background-color: white;
    }
    table th {
          border-width: 1px 1px 1px 1px;
          padding: 2px 2px 2px 2px;
          border-style: inset inset inset inset;
          border-color: black black black black; 
          background-color: #336699;
          
    color: #FFFFFF;
         
    -moz-border-radius: 0px 0px 0px 0px;
    }
    table td {
         
    border-width: 1px 1px 1px 1px;
          padding: 2px 2px 2px 2px;
          border-style: inset inset inset inset;
          border-color: black black black black;
          background-color: white;
          -moz-border-radius: 0px 0px 0px 0px;
    }

    </style> 

    <?php

       // Show an HTML_Table form populated by an array
       // containing employee data.

       // Include the HTML_Table package

       require_once "HTML\Table.php";

       // Assemble the data in an array

       $empl_report = array(
       '0' => array("100","Steven","King","SKING","515.123.4567",
                    "17-JUN-87","AD_PRES","25000","","","90"),
       '1' => array("101","Neena","Kochhar","NKOCHHAR","515.123.4568",
                    "21-SEP-89","AD_VP","17000","","100","90"),
       '2' => array("102","Lex","De Haan","LDEHAAN","515.123.4569",
                    "13-JAN-93","AD_VP","16000","","100","90"),
       '3' => array("103","Alexander","Hunold","AHUNOLD","590.423.4567",
                    "03-JAN-90","IT_PROG","9000","","102","60"),
       '4' => array("104","Bruce","Ernst","BERNST","590.423.4568",
                    "21-MAY-91","IT_PROG","6000","","103","60")
       );

       // Create the table object

       $table = new HTML_Table();

       // Set the headers

       $table->setHeaderContents(0, 0, "Emp ID");
       $table->setHeaderContents(0, 1, "First");
       $table->setHeaderContents(0, 2, "Last");
       $table->setHeaderContents(0, 3, "EMail");
       $table->setHeaderContents(0, 4, "Phone");
       $table->setHeaderContents(0, 5, "Hire Date");
       $table->setHeaderContents(0, 6, "Job ID");
       $table->setHeaderContents(0, 7, "Salary");
       $table->setHeaderContents(0, 8, "Comm Pct");
       $table->setHeaderContents(0, 9, "Mgr ID");
       $table->setHeaderContents(0, 10, "Dept ID");

       // Cycle through the array to produce the table data

       $tot_count = count($empl_report);
       for($rownum = 0; $rownum < $tot_count; $rownum++) {
          for($colnum = 0; $colnum < 11; $colnum++) {
          $table->setCellContents($rownum+1, $colnum, $empl_report[$rownum][$colnum]);
          }
      
    }

       // Output the data

       echo $table->toHTML();

    ?>

    Figure 34-1 shows the output of Listing 34-1.


    Figure 34-1.  Creating a table with HTML_Table


    TWEAKING TABLE STYLES WITH CSS AND HTML_TABLE

    Listng 34-1’s introducton mentions use of a CSS style sheet to tweak the table’s appearance (in this case, color, border, and padding). These styles are applied by using basic CSS principles of overriding the defaul table tag’s attributes with CSS-specific properties. However, when incorporating tables into more complex Web pages, using such a basic CSS strategy won’t be so easy. Fortunately, HTML_Table also supports the ability to tweak tables by passing in table-, header-, row-, and cell-specific attributes. This is accomplished with the HTML_Table() constructor for the table attributes, the SetRowAttributes() method for the headers and rows, and the setCellAttributes() method for cel-specific attributes. For each, you just pass in an associative array of attributes. For example, suppose you want to mark up the table with an id attribute called empl_data. You would instantiate the table like so:

    $table = new HTML_Table("id"=>"empl_data");


    More Database Articles Articles
    More By Apress Publishing

    blog comments powered by Disqus

    DATABASE ARTICLES ARTICLES

    - Completing a Book Inventory Management System
    - Uploading Images for a Book Inventory Manage...
    - Finishing the Add Book Story for a Book Inve...
    - Integration Testing for a Book Inventory Man...
    - User Stories for a Book Inventory Management...
    - Unit Testing a Book Inventory Management Sys...
    - Testing a Book Inventory Management System
    - Implementing Models for a Book Inventory Man...
    - Book Inventory Application: Publishers and B...
    - Handling Publishers in a Book Inventory Mana...
    - Publisher Administration for Book Inventory ...
    - Book Inventory Management
    - Using the SQL Reference Manual
    - Using Oracle SQL Developer with SQL Statemen...
    - Fixing Errors with Oracle SQL Developer


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