function result_to_option($result_set=array(), $value_feild='', $label_field='', $selected_val='', $extra_attr=array(), $lbl_of_lbl='')
{
$_ci = get_instance();
$option = '';
// pr($selectd_val);
if(!empty($result_set))
foreach ($result_set as $key => $value) {
$extr = '';
if(count($extra_attr) > 0){
foreach ($extra_attr as $extattr) {
$extr .= ' data-'.$extattr.'="'.@$value->$extattr.'"';
}
}
$selected = '';
if($selected_val == $value->$value_feild){
$selected = ' selected="selected"';
}
if(is_array($label_field)){
if(count($label_field) > 0){
$lbltext = array();
foreach ($label_field as $lblval) {
$lbltext[] = $value->$lblval;
}
$lbl = implode(' - ',array_filter($lbltext));
}else{
$lbl = $value->$label_field;
}
}else{
$lbl = $value->$label_field;
}
$option .= '<option value="'.$value->$value_feild.'" '.$extr.''.$selected.'>'.strtoupper(trim(preg_replace('/\s+/', ' ',$lbl_of_lbl.' '.$lbl))).'</option>'."\n";
}
return $option;
}
Wednesday, November 29, 2023
PHP : result to select option item
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment