troubleshooting Question

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

Avatar of Eduardo Fuerte
Eduardo FuerteFlag for Brazil asked on
PHPJSONjQueryJavaScriptMySQL Server
14 Comments1 Solution796 ViewsLast Modified:
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>

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




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

    }
 

Thanks in advance!
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 14 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 14 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros