Php > HTML and Php
Keeping selection from a drop down
Keeping selection from a drop down function my_select($name,$rows,$multiple,$array_list,$match) { //this select box takes the above 5 arguements to create details /* 1. $name = the name of the select box 2. $rows = the number of displayed rows (1 as the default) 3. $multiple = does the select allow multiple choices (boolean value 0 for no, 1 for yes 4. $array_list = the options (in a value:display pair ie "1:Informatique","2:Voyages","3:Immobilier") 5. $match = the items to be selected if trying to keep a value ( is "" if no values present or comma separated list if multiple) */ $numOpts = count($match); if ($numOpts>1){ $matches=implode(",",$match); }elseif ($numOpts==1){ $matches=$match; }else{ $matches=""; } echo "
"; $count=count($array_list); for ($i=0;$i<$count;$i++){ //take apart the array key:value pairs $elements = explode(":",$array_list[$i]); //compare matches to list to see if the item is selected if (($numOpts<2)&&($matches == $elements[0])){ echo "
".$elements[1]; }elseif(($numOpts>1)&&(in_array($elements[0],$matches))){ echo "
".$elements[1]; }else{ echo "
".$elements[1]; } }//end for echo "
"; }//end function ?>
Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage