我正在尝试将数组传递到视图页面并将项目放在列表框/下拉列表中。这段代码我哪里出错了?
模型
public function get_suppliers(){
$type = "SUPPLIER";
$this->db->where('usertype', $type);
$query = $this->db->get('users');
foreach ($query->result() as $row){
$results = array(
'userid' => $row->userid,
'firstname' => $row->firstname,
'lastname' => $row->lastname,
'company' => $row->company
);
}
return $results;
}
控制器
$this->load->model('user_model');
$data['supplier']= $this->user_model->get_suppliers();
$this->load->view('include/header.php');
$this->load->view('addvehicle_view', $data);
$this->load->view('include/footer.php');
看法
<?php
if(isset($supplier)){
foreach ($supplier as $info){
echo'<option value="' . $info->userid . '">' . $info->company . ' - ' . $info->lastname . ', ' . $info->firstname . '</option>';
}
}
?>