Created
March 16, 2022 01:17
-
-
Save mdestafadilah/6ff66034115c5150aba821837e3a1626 to your computer and use it in GitHub Desktop.
Dropdown value dari Kolom Database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# source: https://github.com/typesafer/codeigniter-enum-select-boxes | |
if (!function_exists('dropdownKolom')) { | |
function dropdownKolom($table , $field, $all=false) | |
{ | |
$ci = & get_instance(); | |
$query = "SHOW COLUMNS FROM ".$table." LIKE '$field'"; | |
$row = $ci->db->query("SHOW COLUMNS FROM ".$table." LIKE '$field'")->row()->Type; | |
$regex = "/'(.*?)'/"; | |
preg_match_all( $regex , $row, $enum_array ); | |
$enum_fields = $enum_array[1]; | |
foreach ($enum_fields as $key=>$value) | |
{ | |
if ($all) { | |
$enums['all'] = 'All'; | |
$enums[$value] = strtoupper($value); | |
}else{ | |
$enums[$value] = strtoupper($value); | |
} | |
} | |
return $enums; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment