Important alert: (current site time 7/15/2013 9:57:33 AM EDT)
 

VB icon

Automated dropdown list

Email
Submitted on: 12/23/2008 2:45:44 PM
By: [RTS]BN+VS*  
Level: Intermediate
User Rating: Unrated
Compatibility: PHP 4.0, PHP 5.0
Views: 8252
author picture
(About the author)
 
     Function that returns an xhtml dropdown element with a database based options that will be ready to use in a form. More info, examples and updates can be found here http://code.tiko-world.com/forum/viewtopic.php?p=195#195
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
// for :Automated dropdown list
//**************************************
Enjoy!
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: Automated dropdown list
// Description:Function that returns an xhtml dropdown element with a database based options that will be ready to use in a form.
More info, examples and updates can be found here http://code.tiko-world.com/forum/viewtopic.php?p=195#195
// By: [RTS]BN+VS*
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=2566&lngWId=8//for details.//**************************************

function dropDown($name, $elements, $defaultValue = 0, $values = null, $args = '', $retainValue = true)
	{ // By De Dauw Jeroen - December 2008 - jeroen_dedauw@yahoo.com
	 // http://code.tiko-world.com/forum/viewtopic.php?t=81
	$nr = 0;
	if ($retainValue && isset($_REQUEST[$name])) $defaultValue = $_REQUEST[$name];
	foreach($elements as $option)
		{
		$html.="<option value ='".($values != null ? $values[$nr] : $nr)."' ".($defaultValue == ($values != null ? $values[$nr] : $nr) ? 'selected' : '').">$option</option>";
		$nr++;
		}
	return "<select name='$name' $args>$html</select>"; 
	}
function getDropDown($name, $table, $descriptions_field, $values_field = null, $value = 0, $sqlSort = null, $args = null, $retainValue = true)
	{ // By De Dauw Jeroen - December 2008 - jeroen_dedauw@yahoo.com
	if (empty($values_field)) $values_field = $name;
	if (empty($sqlSort)) $sqlSort = "ORDER BY `$descriptions_field` ASC";
	if (empty($args)) $args = "id='$name'";
	return dropDown($name, getOptions($descriptions_field, $table, "", $sqlSort), $value, getOptions($values_field, $table, "", $sqlSort), $args);
	}
function getOptions($select, $from, $where = "", $other = "")
	{ // By De Dauw Jeroen - November 2008 - jeroen_dedauw@yahoo.com
	global $db;
	$options = array();
	$db->Query("SELECT $select FROM $from ".(strlen($where) > 0 ? "WHERE $where" : "").(strlen($other) > 0 ? " $other" : ""));
	while($record = $db->GetObject()) 
		{
		$options[] = $record->$select;
		}	
	return $options;	
	}


Other 11 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.