diff options
| author | Damien Regad <dregad@mantisbt.org> | 2019-05-07 17:44:31 +0200 |
|---|---|---|
| committer | Damien Regad <dregad@mantisbt.org> | 2019-11-24 01:51:00 +0100 |
| commit | 44cacdc45d3208fdb3ae349a644b8ea516cf1973 (patch) | |
| tree | 84956375843a5d8a4818126b1ef4344639e14994 /adodb-lib.inc.php | |
| parent | b6880403b14d3a3cd773dae54bc29c305b991e37 (diff) | |
| download | adodb-44cacdc45d3208fdb3ae349a644b8ea516cf1973.tar.gz adodb-44cacdc45d3208fdb3ae349a644b8ea516cf1973.tar.bz2 adodb-44cacdc45d3208fdb3ae349a644b8ea516cf1973.zip | |
Fix getMenu() for ADODB_FETCH_BOTH
Commit 61c5a8cf0ea9df2777eed7d1bb7935593aa93545 (see #460) introduced a
regression in the behavior of getMenu() when ADODB_FETCH_MODE is set to
ADODB_FETCH_BOTH, causing it to use the recordset's first column for
both the select options' value and description.
Fixes #482
Diffstat (limited to 'adodb-lib.inc.php')
| -rw-r--r-- | adodb-lib.inc.php | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/adodb-lib.inc.php b/adodb-lib.inc.php index 372c02bd..2f94b51d 100644 --- a/adodb-lib.inc.php +++ b/adodb-lib.inc.php @@ -212,10 +212,11 @@ function _adodb_replace(&$zthis, $table, $fieldArray, $keyCol, $autoQuote, $has_ return ($rs) ? 2 : 0; } -// Requires $ADODB_FETCH_MODE = ADODB_FETCH_NUM function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=false, $size=0, $selectAttr='',$compareFields0=true) { + global $ADODB_FETCH_MODE; + $hasvalue = false; if (is_array($name)) @@ -258,13 +259,15 @@ function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=f continue; } - $myFields = array_map('trim',array_values($zthis->fields)); - - if ($fieldsize > 1) { - if (isset($myFields[1])) - $zval2 = $myFields[1]; - else - $zval2 = next($myFields); + if ($fieldsize > 1) { + if ($ADODB_FETCH_MODE == ADODB_FETCH_ASSOC) { + // Get 2nd field's value regardless of its name + $zval2 = current(array_slice($zthis->fields, 1, 1)); + } else { + // With NUM or BOTH fetch modes, we have a numeric index + $zval2 = $zthis->fields[1]; + } + $zval2 = trim($zval2); } $selected = ($compareFields0) ? $zval : $zval2; @@ -291,10 +294,11 @@ function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=f return $s ."\n</select>\n"; } -// Requires $ADODB_FETCH_MODE = ADODB_FETCH_NUM function _adodb_getmenu_gp(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=false, $size=0, $selectAttr='',$compareFields0=true) { + global $ADODB_FETCH_MODE; + $hasvalue = false; if (is_array($name)) @@ -334,13 +338,15 @@ function _adodb_getmenu_gp(&$zthis, $name,$defstr='',$blank1stItem=true,$multipl continue; } - $myFields = array_map('trim',array_values($zthis->fields)); - if ($fieldsize > 1) { - if (isset($myFields[1])) - $zval2 = $myFields[1]; - else - $zval2 = next($myFields); + if ($ADODB_FETCH_MODE == ADODB_FETCH_ASSOC) { + // Get 2nd field's value regardless of its name + $zval2 = current(array_slice($zthis->fields, 1, 1)); + } else { + // With NUM or BOTH fetch modes, we have a numeric index + $zval2 = $zthis->fields[1]; + } + $zval2 = trim($zval2); } $selected = ($compareFields0) ? $zval : $zval2; |
