Ejemplo n.º 1
0
function mysql_enum_field_to_html_options($connect_id, $table, $field, $selected = array(), $add_numbers = 0, $add_null = 0)
{
    #if ( !$connect_id ) return;
    $extracted_field = mysql_field_structure($connect_id, $table, $field, $add_numbers);
    $enum_values = $extracted_field['size'];
    if (is_array($selected)) {
        $selected_array = $selected;
    } else {
        # in order to be backward compatible with old scripts, but its best not to use this manner incase a value had a comma in it
        $selected_array = explode(",", $selected);
    }
    if ($extracted_field['null'] == "YES" and $add_null) {
        $html_output = "<option value=''></option>";
    }
    foreach ($enum_values as $key => $text) {
        if ($add_numbers) {
            if (in_array($text, $selected_array)) {
                $html_output .= "<option value=\"{$key}\" selected>{$text}";
            } else {
                $html_output .= "<option value=\"{$key}\">{$text}";
            }
        } else {
            if (in_array($text, $selected_array)) {
                $html_output .= "<option selected>{$text}";
            } else {
                $html_output .= "<option>{$text}";
            }
        }
        $html_output .= "</option>";
    }
    return $html_output;
}
Ejemplo n.º 2
0
function mysql_enum_field_to_html_options($connect_id, $table, $field, $selected = array(), $add_numbers = 0)
{
    if (!$connect_id) {
        return;
    }
    $extracted_field = mysql_field_structure($connect_id, $table, $field);
    $enum_values = $extracted_field['size'];
    if (is_array($selected)) {
        $selected_array = $selected;
    } else {
        $selected_array = explode(",", $selected);
    }
    foreach ($enum_values as $text) {
        if ($add_numbers) {
            $x++;
            if (in_array($text, $selected_array)) {
                $html_output .= "<option value=\"{$x}\" selected>{$text}";
            } else {
                $html_output .= "<option value=\"{$x}\">{$text}";
            }
        } else {
            if (in_array($text, $selected_array)) {
                $html_output .= "<option selected>{$text}";
            } else {
                $html_output .= "<option>{$text}";
            }
        }
        $html_output .= "</option>";
    }
    return $html_output;
}