Avatar of Eduardo Fuerte
Eduardo Fuerte
Flag for Brazil

asked on 

Could you check why this Codeigniter order by isn't recognised when filling a combobox ?

Hi Experts

Could you check why this Codeigniter order by isn't recognised when filling a combobox ?

img001

jquery code
<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>

Open in new window


Controler Code

  //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); 
    }

Open in new window





Model code
  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);

    }
 

Open in new window


Thanks in advance!
PHPJSONjQueryJavaScriptMySQL Server

Avatar of undefined
Last Comment
Marco Gasi

8/22/2022 - Mon