Database
  Home arrow Database arrow Page 8 - 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 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
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 - Printing


    (Page 8 of 12 )

    Record set objects have two methods that return <select> tags built from the data in the record set: GetMenu() and GetMenu2(). The functions are identical except for how they handle default values (more about that in a few paragraphs). The functions use the first column in the record set as the labels for each option and the second column as the values. If you have an ID column and aname column in a table, put the name column first and the ID column second in your query:

    $rs = $conn->execute('SELECT flavor,id FROM ice_cream');
    print $rs->GetMenu('which_flavor');

    This prints the following <select> menu:

    <select name="which_flavor" >
    <option></option>
    <option value="1">Chocolate</option>
    <option value="2">Vanilla</option>
    <option value="3">"Heavenly" Hash</option>
    <option value="4">Diet Cardboard</option>
    </select>

    The first argument to GetMenu() is used as the name attribute of the <select> tag. The <option> tags are printed one per line in the order that their rows appear in the result set. HTML entities, such as the quotation marks in "Heavenly" Hash, are encoded.

    To have one <option> tag marked as selected so the browser treats it as the default value, pass the label for that tag as the second argument to GetMenu():

    $rs = $conn->execute('SELECT flavor,id FROM ice_cream');
    print $rs->GetMenu('which_flavor','Vanilla');

    This produces the following:

    <select name="which_flavor" >
    <option></option>
    <option value="1">Chocolate</option>
    <option selected value="2">Vanilla</option>
    <option value="3">"Heavenly" Hash</option>
    <option value="4">Diet Cardboard</option>
    </select>

    Default value handling is where GetMenu() and GetMenu2() differ. The GetMenu2() function marks a choice as selected when its value matches the second argument passed in. To make Vanilla the default with GetMenu2(), pass 2 as a second argument:

    $rs = $conn->execute('SELECT flavor,id FROM ice_cream');
    print $rs->GetMenu2('which_flavor',2);

    This prints the same menu as in the previous example.

    The menus that you’ve produced with GetMenu() and GetMenu2() so far all have an initial blank option. This is useful for checking that a user has selected an option in mandatory fields. If you want to turn it off, pass false as the third argument to either function:

    $rs = $conn->execute('SELECT flavor,id FROM ice_cream');
    print $rs->GetMenu2('which_flavor',null,false);

    This produces a menu without an initial blank option:

    <select name="which_flavor" >
    <option value="1">Chocolate</option>
    <option value="2">Vanilla</option>
    <option value="3">"Heavenly" Hash</option>
    <option value="4">Diet Cardboard</option>
    </select>

    By passing null as the second argument to GetMenu2(), you avoid setting any option to selected while still being able to specify that you don’t want an initial blank.

    The next two arguments to GetMenu() and GetMenu2() control whether the user is allowed to select multiple options of the menu and, if so, how many options to display at once. These arguments set the multiple and size attributes of the <select> tag. To set the multiple attribute, pass true as a fourth argument. To set the size attribute, pass the value to set size to as the fifth argument. The size attribute is only relevant if the multiple attribute is set. If multiple is set, then the menu name has square brackets appended to it. This tells PHP to treat the submitted form values as an array. The following is an example:

    $rs = $conn->execute('SELECT flavor,id FROM ice_cream');
    print $rs->GetMenu('which_flavor',null,false,true,3);

    This produces the following menu:

    <select name="which_flavor[]" multiple size=3 >
    <option value="1">Chocolate</option>
    <option value="2">Vanilla</option>
    <option value="3">"Heavenly" Hash</option>
    <option value="4">Diet Cardboard</option>
    </select>

    The sixth argument to the menu functions is a string containing additional attributes for the <select> tag. You can use this argument to specify values for a style, class, or other attribute. If you want to pass additional attributes in this argument, you need to fill in defaults or appropriate values for all of the preceding arguments:

    $rs = $conn->execute('SELECT flavor,id FROM ice_cream');
    print $rs->GetMenu('which_flavor',null,false,null,null,'class="bigselect"');

    This adds the class="bigselect" attribute to the <select> tag:

    <select name="which_flavor" class="bigselect">
    <option value="1">Chocolate</option>
    <option value="2">Vanilla</option>
    <option value="3">"Heavenly" Hash</option>
    <option value="4">Diet Cardboard</option>
    </select>

    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

    - 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
    - Manipulating ADO Recordsets





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway