One of the more common problems is how to keep a selection from a drop down chosen by the user show up again.
I created the below function which will handle both single choice and multiple choice drop down values and mark them as selected when the user views that drop down again.
Hope it make life easier for someone...
bastien
By : bastien
<? 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)
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 "<option value=\"".$elements[0]."\" SELECTED>".$elements[1]; }elseif(($numOpts>1)&&(in_array($elements[0],$matches))){ echo "<option value=\"".$elements[0]."\" SELECTED>".$elements[1]; }else{ echo "<option value=\"".$elements[0]."\">".$elements[1]; } }//end for echo "</select>";
}//end function ?>
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.