Database
  Home arrow Database arrow Page 6 - Accessing Databases with ADODB
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATABASE

Accessing Databases with ADODB
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 37
    2004-08-02

    Table of Contents:
  • Accessing Databases with ADODB
  • Connecting, Queries and Quoting
  • Introducing Record Sets
  • Retrieving Multiple Rows
  • Understanding Error Handling
  • Generating HTML
  • More HTML Generation
  • Printing
  • Splitting Data Across Multiple Pages
  • Pivot Tables
  • Caching
  • Exporting Data

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Accessing Databases with ADODB - Generating HTML


    (Page 6 of 12 )

    ADODB makes it very easy to perform common HTML generation tasks with information retrieved from a database. These tasks include displaying a record set in an HTML table, printing <select> tags containing data from a record set, and splitting data from a record set across multiple pages.

    Displaying a Record Set in an HTML Table

    The rs2html() function produces an HTML table of results with just one function call. The function is defined in the adodb/tohtml.inc.php file, so you must include or require that file to use rs2html(). Just pass a record set to rs2html(), and it prints an HTML table:

    require 'adodb/tohtml.inc.php';
    // Assume $conn is a valid database connection
    $rs = $conn->execute('SELECT flavor,calories,price FROM ice_cream');
    rs2html($rs);

    This prints the following HTML:

    <table COLS=3 BORDER='1' WIDTH='98%'>

    <TH>flavor</TH><TH>calories</TH><TH>price</TH>

    <TR valign=top>
         <TD>Chocolate </TD>
         <TD align=right>10 </TD>
         <TD align=right>4.50 </TD>

    </TR>

    <TR valign=top>
         <TD>Vanilla </TD>
         <TD align=right>20 </TD>
         <TD align=right>4.50 </TD>

    </TR>

    <TR valign=top>
         <TD>"Heavenly" Hash </TD>
         <TD align=right>60 </TD>
         <TD align=right>5.95 </TD>

    </TR>

    <TR valign=top> 
         <TD>Diet Cardboard </TD> 
         <TD align=right>0 </TD>
         <TD align=right>1.15 </TD>

    </TR>

    </table>

    Figure 2-1 shows a rendered version of the HTML table.



    Figure 2-1. The rs2html() function generates an HTML table.

    By default, the table produced by rs2html() has BORDER='1' WIDTH='98%' as the attributes for the <table> tag, but you can override those defaults by passing different attributes as a second argument to rs2html(). Using the record set from the previous example, rs2html($rs,'CLASS="fancytable"') prints a table whose opening tag is as follows:

    <table COLS=3 CLASS="fancytable">

    You can also change the text of the table’s header row. By default, rs2html() uses the column names in the result set, but if an array of strings is passed as the third argument to rs2html(), it uses the values in that array instead. Using the record set from the previous example, rs2html($rs,false,array('Ice Cream Flavor','Calorie Count','Cost')) prints a table whose header row is as follows:

    <TH>Ice Cream Flavor</TH>
    <TH>Calorie Count</TH><TH>Cost</TH>

    By passing false as a second argument to rs2html() in this example, you tell the function to use the defaults for <table> tag attributes.

    The fourth argument to rs2html() is a boolean that controls whether string values in the table have their HTML entities encoded by htmlentities(). It defaults to true. If you don’t want those values to have their entities encoded, pass false. This doesn’t affect entity encoding of the values in the table header row. When rs2html() uses the column names from the result set, it always encodes their HTML entities. When it uses column names passed in as its third argument, it never encodes their HTML entities.

    This is from Essential PHP Tools, by David Sklar (Apress, ISBN 1590592808). Check it out at your favorite bookstore today. Buy this book now.

    More Database Articles
    More By Apress Publishing


       · i want the programming code for the add delete update useing the adodb ontrols.
     

    DATABASE ARTICLES

    - Excel Reference
    - Database Programming in C# with MySQL : Usin...
    - Formatting Techniques for Data Access from E...
    - Data Access from Excel VBA
    - Generating a Multiple Table Crystal Report u...
    - ADO and the Command Object
    - On Wiring Up an ADO Data Control
    - Reading and Writing to Files on the Intranet
    - Using ADO Record to Create and Navigate Intr...
    - Using Data Access Pages to Access Data on a ...
    - Using ADO with the SQL Native Client
    - ADO`s Stream Object
    - Opening a Record Object Referencing an Open ...
    - Introducing Jasper (SQL Anywhere 10 Beta)
    - Creating a Database Project in VS 2005

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT