ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:reference:recordset:getmenu3

This is an old revision of the document!


getMenu3

This method requires that ADODB_FETCH_MODE be set to ADODB_FETCH_NUM prior to execution of the SQL statement that will provide the recordset.

Syntax
string getMenu3(
    optional string $selectName='',
    optional mixed $defaultValue=false,
    optional bool $blankFirstItem=true,
    optional bool $multiple=false,
    optional int $numberOfRows=0,
    optional string $optionalAttributes='',
    optional bool $compareSelectedCol0=true
    )

Description

The function getMenu3() Generates an HTML OPTGROUP select string from a recordset, and returns the string. The recordset requires 3 columns, the 3rd being used for the optgroup. The select can be defined as either a single or multiple select

Parameters

$selectName

name of SELECT tag

$defaultValue

The value to highlight. Use an array for multiple highlight for listbox.

$blankFirstLine

true to leave the 1st item in list empty

$multiple

Set true to create a multi-select box

$numberOfRows

Number of rows to show for multi-select box. If not a multi-select, this field has no meaning.

$optionalAttributes

Additional attributes to defined for SELECT tag, useful for holding javascript onChange='…' handlers or class information. Note that by default, the select box is generated without an id, so this should be included here.

$compareSelectedCol0

When we determine the selected tag, by default we compare the value provided against the first column in the recordset (the option value). By changing this to false, we compare the value against the second.

Usage

/*
* Connect to DB2 Sample Database
*/
$db->setFetchMode(ADODB_FETCH_NUM);
$SQL = "SELECT actdesc,actno,actgroup FROM act ORDER BY actgroup, actno
$result = $db->execute($SQL);
 
$html = $result->getMenu3('mySelect','30',true,true,10,'id="mySelect" class="myclass-1 myclass-2");
 
print $html
<select name="mySelect[]" multiple size="10" id="mySelect" class="myclass-1 myclass-2">
<option></option>
<optgroup label='ANALYSIS/DESIGN'>
<option value='10'>MANAGE/ADVISE</option>
<option value='20'>ESTIMATE COST</option>
<option selected='selected' value='30'>DEFINE SPECS</option>
<option value='40'>LEAD PROGRAM/DESIGN</option>
<option value='50'>WRITE SPECS</option>
<option value='60'>DESCRIBE LOGIC</option>
</optgroup>
<optgroup label='PROGRAM/TEST/INSTALL'>
<option value='70'>CODE PROGRAMS</option>
<option value='80'>TEST PROGRAMS</option>
<option value='90'>ADM QUERY SYSTEM</option>
</optgroup>
<optgroup label='POST INSTALLATION'>
<option value='100'>TEACH CLASSES</option>
<option value='110'>DEVELOP COURSES</option>
<option value='120'>PERS AND STAFFING</option>
<option value='130'>OPER COMPUTER SYS</option>
<option value='140'>MAINT SOFTWARE SYS</option>
<option value='150'>ADM OPERATING SYS</option>
<option value='160'>ADM DATA BASES</option>
<option value='170'>ADM DATA COMM</option>
<option value='180'>DOCUMENT</option>
</optgroup>
</select>
v5/reference/recordset/getmenu3.1546376968.txt.gz · Last modified: 2019/01/01 22:09 by mnewnham