Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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