我无法通过连接mysql数据库中的名字和姓氏来填充下拉列表。我尝试了一些查询,但没有一个似乎工作。我知道我在查询中有错误,但无法弄清楚发生了什么。我也粘贴了我的MVC代码以及我的表格的图像。使用从Mysql数据库返回的值填充下拉列表
我的控制器的代码是:exits.php
function admin_add_absconding(){
global $SITE,$USER;
$data = array();
$data['row'] = new stdClass();
$data['row'] = $this->admin_init_elements->set_post_vals($this->input->post());
$data['offices']=$this->mod_common->get_all_offices();
$clients = currentuserclients();
$data['roles'] = $this->mod_common->get_cat_array('designation','status',"1' AND id > '0",'designation');
get_city_state_country_array($data,array('cityid'=>$data['row']->cityid));
$data['error_message'] = '';
$data['row']->id = $this->uri->segment(3);
$data['id'] = $this->uri->segment(3);
$data['action'] = 'add';
$data['heading'] = 'Add';
$data['msg_class'] = 'sukses';
$data['path']=$path;
$post_action = $this->input->post('action');
$data['groups'] = $this->exit_common->get_all_names();
if($post_action=='add' || $post_action =='update'){
$post_array = $this->input->post();
$action = ($post_action == 'add')?'inserted':'updated';
//echo '<pre>';print_r($SITE);die;
echo $post_array['exit_type'] = 'Employee Initiated';
if($data['error_message'] == 'Record '.$action.' successfully'){
$data['row'] = new stdClass();
$data['row']->id = $this->uri->segment(3);
$data['row']->status = 1;
}
}
我的模型代码是:exit_common.php
function get_all_names(){
$query = $this->db->query('SELECT firstname,lastname FROM pr_users_details');
echo $this->db->last_query();
die;
return $query->result();
}
我的视图的代码是:backend_add_new_exit.php
<select class="form-control">
<?php
foreach($groups as $row)
{
echo '<option value="'.$row->firstname.'">'.$row->lastname.'</option>';
}
?>
</select>
什么是错误?解释更多。不清楚 –
为什么不在MySQL中创建名称:SELECT concat(firstname,'',lastname)作为名称 – user3741598
解决了..但是视图未从控制器正确呈现 – shank