-2

Possible Duplicate:
PHP: “Notice: Undefined variable” and “Notice: Undefined index”

I try to load combo box content from database. But when I run the code I get undefined variable message. What I did is load data from the database table and in the model then use them in controller to send an array of data to view.

Here is the controller method

public function loadcombo(){

       //Calling the getcombo_titel() function to get the arr of titles. Model already loaded.
        $arrStates = $this->dataOperateModel->getcombo_titel();
        print_r($arrStates);
        echo 'hiii';
        //Getting the final array in the form which I will be using for the form helper to create a dropdown.
        foreach ($arrStates as $job_name) {
            $arrFinal[$job_name->title] = $job_name->title;
        }

        $data['job_name'] = $arrFinal;
        $data['main_content']='home/welcome_message';
        print_r($arrFinal);

        //$data['states'] = $arrFinal;
        //$data['main_content']='user/index_view';
        //Passing $data to the view, so that we can get the states as an array inside the view.
        $this->load->view('layout',$data);


        }

Here is code in view

 <div class="content" id="desc" >Job title</div> <div id="cont" class="content">

                   <?php echo form_dropdown('job_name',$job_name); ?>
 </div>

In the error it says "Undefined variable: job_name"

Here is the code for the model

 public function getcombo_titel(){
        $query = $this->db->query("SELECT DISTINCT title FROM combo_jobtitle");

        if ($query->num_rows > 0) {
            return $query->result();
        }
   }

Can anybody tell, where I have done the mistake?

Community
  • 1
  • 1
kiriappa
  • 822
  • 2
  • 7
  • 14

1 Answers1

0

problem was in the sql query. I had mispelled the word tittle. sorry guys.

kiriappa
  • 822
  • 2
  • 7
  • 14