We help IT Professionals succeed at work.
Get Started

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

Last Modified: 2015-12-17
Hi Experts

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


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();
 			type: 'post',
            //url: baseurl + "edital/get_orgao_items",
            url: baseurl + "acesso_usuarios/get_orgao_items",
            data: {idprograma: idprograma},
 			dataType: 'json',
			success: function (result)
	           $.each(result, function(i, item)
		          $('#orgao').append("<option value='" + i + "'>" + item + "</option>");
			error: function (result)
				alert('Ocorreu algum erro.');

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->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!
Watch Question
Most Valuable Expert 2020
Most Valuable Expert 2018
This problem has been solved!
Unlock 1 Answer and 14 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE