Php 无法将数据加载到codeigniter中的组合框
可能重复:Php 无法将数据加载到codeigniter中的组合框,php,codeigniter,Php,Codeigniter,可能重复: 我尝试从数据库加载组合框内容。但是当我运行代码时,我得到了未定义的变量消息。我所做的是从数据库表和模型中加载数据,然后在控制器中使用它们来发送数据数组以供查看 这里是控制器方法 public function loadcombo(){ //Calling the getcombo_titel() function to get the arr of titles. Model already loaded. $arrStates = $this-&g
我尝试从数据库加载组合框内容。但是当我运行代码时,我得到了未定义的变量消息。我所做的是从数据库表和模型中加载数据,然后在控制器中使用它们来发送数据数组以供查看 这里是控制器方法
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>
有人能告诉我,我在哪里犯了错误吗?问题出在sql查询中。我把“title”这个词拼错了。抱歉,伙计们。确保您的数据在
$arrStates
中……讽刺的是,您的答案中又错了一个方面。
public function getcombo_titel(){
$query = $this->db->query("SELECT DISTINCT title FROM combo_jobtitle");
if ($query->num_rows > 0) {
return $query->result();
}
}