Location: PHPKode > scripts > MySQLDropDownCondiff > mysqldropdowncondiff/SQLDropDown.php
<?php
require_once 'config.php';

class SQLDropDown
{
	
	function SQLDropDown($connect_db){
		if($connect_db == true){
			$this->db_connection = mysql_connect(SERVER_NAME, DB_USER, DB_PASSWORD) or die ('Unable to connect to Database!');
			mysql_select_db(DB_NAME);
		}
	}
	
	function sql_drop_down($sql_statement, $name, $display_field, $id_field, $selected_field='',$selected_value=''){
		$result = mysql_query($sql_statement);  
		$numOfCols = mysql_num_rows($result);
		$select_html = '<select name="'.$name.'">';
		if($numOfCols > 0){
			
			for($i = 0; $i < $numOfCols; $i++)
			{
				$id = mysql_result($result, $i, $id_field);
				$display = mysql_result($result, $i, $display_field);
				if($selected_value == $id){
					$select_html.= '<option selected="yes" value="'.$id.'">'.$display.'</option>';
				}
				else{
					$select_html.= '<option value="'.$id.'">'.$display.'</option>';
				}
			}
			$select_html.= '</select>';
		}
		else{
			$select_html = "Error Occured...";
		}
		return $select_html;
		
	}
	
}
Return current item: MySQLDropDownCondiff