<?php
function pilihan_dinamis($name, $table, $field, $field2, $pk, $selected)
{
    $ci = get_instance();
    $cmb = "<select name='$name' class='form-control'>";
    $cmb .= "<option value=''>-Pilih-</option>";
    $data = $ci->db->get($table)->result();
    foreach ($data as $d) {
        $cmb .= "<option value='" . $d->$pk . "'";
        $cmb .= $selected == $d->$pk ? " selected='selected'" : '';
        $cmb .= ">" .  ucwords(strtolower($d->$field)) . " , " .  $d->$field2 . "</option>";
    }
    $cmb .= "</select>";
    return $cmb;
}
