0
我在下拉菜單中顯示數據庫內容時遇到問題。這是代碼。請給我一個解決方案在MySQL數據庫中使用Codeignitter和Bootstrap下拉菜單
模型m_admin.php
public function getSiteList(){
$result = array();
//$query = $this->db->query("SELECT * FROM Table_Site ORDER BY ASC");
$this->db->select('*');
$this->db->from('Table_Site');
$this->db->order_by('siteName','ASC');
$array_keys_values = $this->db->get();
foreach ($array_keys_values->result() as $row)
{
$result[0]= '-Select Site-';
$result[$row->siteName] = $row->siteId;
}
return $result;
}
這是控制器(admin.php的)
public function company()
{
if($this->session->userdata('isLogin')== FALSE)
{
redirect('login/login_form');
}else
{
$user = $this->session->userdata('username');
$data['level'] = $this->session->userdata('level');
$data['pengguna'] = $this->m_login->dataPengguna($user);
}
$this->load->model('m_admin');
$data['site_list'] = $this->m_admin->getSiteList();
$this->load->view('css/header');
$this->load->view('css/topnav',$data);
$this->load->view('admin/adminmenu');
$this->load->view('admin/companylist');
$this->load->view('css/js');
$this->load->view('css/footer');
}
這是視圖(companylist.php)
<?php
foreach($site_list as $each){ ?>
<option value="<?php=.$each['siteId']?>"><?php=$each['siteName']?></option>
<?php }?>
什麼是你所得到的錯誤? – palerdot
下拉菜單無法顯示siteName的內容。 –