Library /lib/fields/class.dbTextSelectField.php

Language PHP Lines 70
MD5 Hash 7e1dd0a3eea0240d26430217f1bfba11
Repository https://github.com/reshadf/Library.git View Raw File
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
 * class dbTextSelectField
 *
 * Create a TextSelect field from records retrieved from the db
 *
 * @author Johan Wiegel
 * @package FormHandler
 * @subpackage Fields
 * @since 22-10-2008
 */

class dbTextSelectField extends TextSelectField
{
    var $_oDb;
	var $_aOptions;		

    /**
     * dbTextSelectField::dbTextSelectField()
     *
     * Public constructor: create a new dbTextSelectField object
     *
     * @param object &$oForm: the form where the TextSelectfield is located on
     * @param string $sName: the name of the datefield
     * @param object $oDb: object of the database handler
     * @param string $sTable: the table to get the fields from
     * @param mixed $sField: array of string with the name of the field which data we should get
     * @param string $sExtraSQL: extra SQL statements
     * @return dbTextSelectField
     * @access public
     * @since 22-10-2008
     * @author Johan Wiegel
     */
	function dbTextSelectField( &$oForm, $sName, &$oDb, $sTable, $sField, $sExtraSQL = null, $sMask = null )
	{
		// generate the query to retrieve the records
		$sQuery =
		  'SELECT '.$sField.
		  ' FROM '. $oDb->quote( $sTable).' '.$sExtraSQL;

		$this->_aOptions = array();

		
		// execute the query
		$sql = $oDb->query( $sQuery );

		// query succeeded
		if( $sql )
		{
    		while( $row = $oDb->getRecord( $sql ) )
    		{
    			$this->_aOptions[] = $row[$sField];
    		}
		}
		// query failed
		else
		{
		    trigger_error(
		      "Error, could not retrieve records.<br '. FH_XHTML_CLOSE .'>\n".
		      "Error message: ". $oDb->getError()."<br '. FH_XHTML_CLOSE .'>\n".
		      "Query: ". $sQuery,
		      E_USER_WARNING
		    );
		}
			    // call the constructor of the selectfield
		parent::TextSelectField( $oForm, $sName, $this->_aOptions );

 	}
}
?>
Back to Top