Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.4.0

Request #8060 HTML_QuickForm_select -> loadDbResult Support MDB2
Submitted: 2006-06-28 16:47 UTC
From: dvilches at gmail dot com Assigned:
Status: Wont fix Package: HTML_QuickForm2 (version 3.2.6)
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: (Not assigned)    
Subscription  


 [2006-06-28 16:47 UTC] dvilches at gmail dot com (dvilches)
Description: ------------ I changed the method loadDbResult in HTML_QuickForm_select. Test script: --------------- require_once 'MDB2.php'; $dsn = array('phptype' => DB_PHPTYPE, 'username' => DB_USER, 'password' => DB_PWD, 'hostspec' => DB_HOST, 'database' => DB_DATABASE, ); $db = MDB2::factory($dsn); if (Pear::isError($db)){ die($db->getMessage()); } $db->setFetchMode(MDB2_FETCHMODE_ASSOC); $sql = "Select table_id, descrip From table"; $element = &HTML_QuickForm::createElement('select', 'table_id', 'Descrip'); $result = $db->query($sql); $element->addOption('',''); $element->loadDbResult($result, 'descrip', 'table_id'); $element->toHtml(); The change of this method is: if (!is_object($result) || !is_a($result, 'db_result')) { .... by if (!is_object($result) || (!is_a($result, 'db_result') && !is_a($result, 'mdb2_result'))) { ... And works for me... Expected result: ---------------- <select name="table_id"> <option value=""></option> <option value="1" selected="selected">Descrip 1</option> <option value="2">Descrip 2</option> <option value="3">Descrip 3</option> </select> Actual result: -------------- <select name="table_id"> <option value=""></option> </select>

Comments

 [2006-07-12 11:47 UTC] dvilches at gmail dot com
I changed the bug type for this item.
 [2006-10-06 15:45 UTC] avb (Alexey Borzov)
Feature requests go to HTML_QuickForm2
 [2006-11-10 11:34 UTC] buye at libero dot it (Carlo Busetto)
Also changed this code in method loadDbResult for supporting MDB2: function loadDbResult(&$result, $textCol=null, $valueCol=null, $values=null) { if (!is_object($result) || !is_a($result, 'db_result') && !is_a($result, 'mdb2_result')) { return PEAR::raiseError('Argument 1 of HTML_Select::loadDbResult is not a valid DB_result'); } if (isset($values)) { $this->setValue($values); } if (is_a($result, 'db_result')) { $fetchMode = ($textCol && $valueCol) ? DB_FETCHMODE_ASSOC : DB_FETCHMODE_ORDERED; } else if (is_a($result, 'mdb2_result')) { $fetchMode = ($textCol && $valueCol) ? MDB2_FETCHMODE_ASSOC : MDB2_FETCHMODE_ORDERED; } while (is_array($row = $result->fetchRow($fetchMode)) ) { if (($fetchMode == DB_FETCHMODE_ASSOC) || ($fetchMode == MDB2_FETCHMODE_ASSOC)){ $this->addOption($row[$textCol], $row[$valueCol]); } else { $this->addOption($row[0], $row[1]); } } return true; } // end func loadDbResult Remember to use getDatabaseResult() for saving result of a query.
 [2012-04-08 17:16 UTC] avb (Alexey Borzov)
-Status: Open +Status: Wont fix
Most of DB abstraction layers implement a fetchAll() method or some analog. These can return an associative array that can be fed to loadOptions(), so no sense bloating the element with additional code.