Skip to content

Instantly share code, notes, and snippets.

@mdestafadilah
Created March 16, 2022 01:17
Show Gist options
  • Save mdestafadilah/6ff66034115c5150aba821837e3a1626 to your computer and use it in GitHub Desktop.
Save mdestafadilah/6ff66034115c5150aba821837e3a1626 to your computer and use it in GitHub Desktop.
Dropdown value dari Kolom Database
# 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