asked on
<script type="text/javascript">
var baseurl = "http://www.codeagro.sp.gov.br/";
$( document ).ready(function(){
$('#programa').on('change', function()
{
var idprograma = $(this).val();
//alert(idprograma);
$.ajax({
type: 'post',
//url: baseurl + "edital/get_orgao_items",
url: baseurl + "acesso_usuarios/get_orgao_items",
data: {idprograma: idprograma},
dataType: 'json',
success: function (result)
{
$('#orgao').children().remove();
$.each(result, function(i, item)
{
$('#orgao').append("<option value='" + i + "'>" + item + "</option>");
});
},
error: function (result)
{
alert('Ocorreu algum erro.');
}
});
});
});
</script>
//EF 2015 Dez01 atualização do combo
public function get_orgao_items(){
$idprograma = $this->input->post('idprograma');
$orgao_items = $this->edital_model->get_orgao($idprograma);
echo json_encode($orgao_items);
}
function get_orgao($idprograma = 0)
{
$this->db->select('idorgao');
$this->db->select('nome');
$this->db->from('tb_orgao');
$this->db->where('idprograma', $idprograma);
// ------ Relevant line -------------------------
$this->db->order_by('nome ');
//----------------------------------------------------
$query = $this->db->get();
$result = $query->result();
// $sql = "SELECT idorgao, nome FROM tb_orgao WHERE idprograma =".$idprograma. " ORDER BY nome";
// $result = $this->db->query($sql);
//array to store idorgao & nome
$idorgao = array('-SELECT-');
$nome = array('-SELECT-');
for ($i = 0; $i < count($result); $i++)
{
array_push($idorgao, $result[$i]->idorgao);
array_push($nome, $result[$i]->nome);
}
return $department_result = array_combine($idorgao, $nome);
}