Location: PHPKode > scripts > DDcomboBox > ddcombobox/class.DDcomboBox.php
<?php

/*
     Class Name: DDcomboBox
     Author: Davis D. Dimalen (hide@address.com)
     Date Created:  05/20/2003
	 Description: This is a simple php component that populates a listbox with data from a
	              recordset created from a PostgresSQL database.
*/

class DDcomboBox
{
     var $tblName;
     var $RowLabel;
	 var $RowValue;
	 var $SelectedValue;
	 var $ComboStr;
	 
     function DDComboBox( $tblName, $RowLabel, $RowValue, $SelectedValue, $ComboStr )
	 {
		$this->tblName = $tblName;  			// Table name
		$this->RowLabel = $RowLabel;			// Option label
		$this->RowValue = $RowValue;			// Option value
		$this->SelectedValue = $SelectedValue;	// The selected option value
		$this->ComboStr = $ComboStr;			// pg_connect connection string

		$ComboCon =pg_connect($this->ComboStr);		
		$ComboQuery = "SELECT * FROM ".$this->tblName;

		$ComboQuery_exec = pg_query($ComboCon, $ComboQuery);
		$ComboNumrows = pg_num_rows($ComboQuery_exec);
		
		for ($ComboIndex = 0; $ComboIndex < $ComboNumrows ; $ComboIndex++)
		{
			$ComboRow = pg_fetch_row($ComboQuery_exec, $ComboIndex);
			if ($ComboRow[pg_field_num($ComboQuery_exec,$this->RowValue)] == $this->SelectedValue)
			{
				echo "<option value=".$ComboRow[pg_field_num($ComboQuery_exec,$this->RowValue)]." selected>".$ComboRow[pg_field_num($ComboQuery_exec,$this->RowLabel)]."</option>";
			}else
			{
				echo "<option value=".$ComboRow[pg_field_num($ComboQuery_exec,$this->RowValue)].">".$ComboRow[pg_field_num($ComboQuery_exec,$this->RowLabel)]."</option>";
			}
		}
	 }
}
?>
Return current item: DDcomboBox