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

Request #8060 HTML_QuickForm_select -> loadDbResult Support MDB2
Submitted: 2006-06-28 11:47 UTC Modified: 2006-10-06 10:45 UTC
From: dvilches at gmail dot com Assigned:
Status: Open Package: HTML_QuickForm2 (version 3.2.6)
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: (Not assigned)    
Subscription  
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes. If this is not your bug, you can add a comment by following this link. If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dvilches at gmail dot com
New email:
PHP Version: Package Version: OS:

 

 [2006-06-28 11: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 06:47 UTC] dvilches at gmail dot com
I changed the bug type for this item.
 [2006-10-06 10:45 UTC] avb (Alexey Borzov)
Feature requests go to HTML_QuickForm2
 [2006-11-10 06: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.