html - PHP mutliselect from three tables selected -
am sorry don't know have ask basically. have been string data in 3 tables. community table storing communities community has types of homes single family, multi family etc , string hometypeid (home types) , commid (community ) in third table.
my problem have show values selected in multi select box when going edit this. have used 2 below functions not these worked problem.
function showoptionsdrop($array, $active, $echo=true){ $string = ''; foreach($array $k => $v){ if(is_array($active)) $s = (in_array($k, $active))? ' selected="selected"' : ''; else $s = ($active == $k)? ' selected="selected"' : ''; $string .= '<option value="'.$k.'"'.$s.'>'.$v.'</option>'."\n"; } if($echo) echo $string; else return $string; } and other function creating multi drop down box.
/** * @multi select dropdown menu * * @param string $name * * @param array $options * * @param array $selected (default null) * * @param int size (optional) * * @return string * **/ function multi_dropdown( $name, array $options, array $selected=null, $size=4 ) { /*** begin select ***/ $dropdown = '<select name="'.$name.'" id="'.$name.'" size="'.$size.'" multiple>'."\n"; /*** loop on options ***/ foreach( $options $key=>$option ) { /*** assign selected value ***/ $select = in_array( $option, $selected ) ? ' selected' : null; /*** add each option dropdown ***/ $dropdown .= '<option value="'.$key.'"'.$select.'>'.$option.'</option>'."\n"; } /*** close select ***/ $dropdown .= '</select>'."\n"; /*** , return completed dropdown ***/ return $dropdown; }
Comments
Post a Comment