Skip to content

Instantly share code, notes, and snippets.

@jrmadsen67
Created January 5, 2013 08:00
Show Gist options
  • Save jrmadsen67/4460432 to your computer and use it in GitHub Desktop.
Save jrmadsen67/4460432 to your computer and use it in GitHub Desktop.
A CodeIgniter dynamic dropdown to allow common languages to appear both at the top of the list and in order
function full_languages_dropdown($id='' )
{
$ci = &get_instance();
$ci->load->model('language_model');
$common_languages = $ci->language_model->order_by('language', 'asc')->get_many_by(array('common'=>1));
$languages = $ci->language_model->order_by('language', 'asc')->dropdown('id', 'language');
$html = '<select id="'.$id.'" name="'.$id.'">';
if (!empty($common_languages))
{
foreach ($common_languages as $key => $common_language) {
$html .= '<option value="'. $common_language->id .'">'. $common_language->language .'</option>';
}
//separator
$html .= '<option value=""> ------ </option>';
}
if (!empty($languages))
{
foreach ($languages as $key => $language) {
$html .= '<option value="'. $key .'">'. $language .'</option>';
}
}
$html .= '</select>';
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment