无法将数据加载到codeigniter中的组合框

时间:2012-12-26 06:00:07

标签: php codeigniter

  

可能重复:
  PHP: “Notice: Undefined variable” and “Notice: Undefined index”

我尝试从数据库加载组合框内容。但是当我运行代码时,我得到了未定义的变量消息。我所做的是从数据库表和模型中加载数据,然后在控制器中使用它们发送一组数据进行查看。

这是控制器方法

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


        }

以下是视图中的代码

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

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

在错误中显示"Undefined variable: job_name"

以下是模型的代码

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

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

有谁可以告诉我,我在哪里犯了错误?

1 个答案:

答案 0 :(得分:0)

问题出在sql查询中。我拼错了tittle这个词。对不起伙计们。