我想在文本框中显示会话数据。我使用以下模型获取ID,并在下拉菜单中显示数据。但是我不知道如何从数据库中的会话中获取[id_dosen]
。我该怎么办?
这是我的_dosen_model.php _:
public function getDosen(){
$this->db->order_by('id_dosen','ASC');
$dosen= $this->db->get('dosen');
return $dosen->result_array();
}
这是我登录的控制器:
public function login() {
$user = $_POST['user'];
$pass = $_POST['pass'];
$QuerySaya = $this->db->query(
"SELECT * FROM user LEFT JOIN mahasiswa ON user.id_user=mahasiswa.id_user LEFT JOIN dosen ON user.id_user=dosen.id_user
WHERE user.username='$user' AND user.password='$pass';"
);
if ($QuerySaya->num_rows() == 0) {
$this->load->view('login');
} else {
$data = $QuerySaya->row();
$this->session->set_userdata('id_admin_ti', $data->id_user);
$this->session->set_userdata('username', $data->username);
$this->session->set_userdata('password', $data->password);
$this->session->set_userdata('level_user', $data->level_user);
$this->session->set_userdata('id_kelas', $data->id_kelas);
$this->session->set_userdata('id_dosen', $data->id_dosen);
$this->session->set_userdata('id_mhs', $data->id_mhs);
$level = $this->session->userdata('level_user');
if ($level == 'mahasiswa') {
$this->load->view('dashboard_mhs', $data);
}else if($level == 'admin'){
$this->load->view('dashboard', $data);
}else if($level == 'dosen'){
$this->load->view('dashboard_dosen', $data);
}
}
}
这是我的观点:
<select id="dosen" name="dosen" class="required form-control input-xs" placeholder="Mata Kuliah" type="text" required="required">
<option>-Nama Dosen-</option>
<?php
foreach ($dosen as $a) {
echo "<option value=".$a['id_dosen'].">".$a['nama_dosen']."</option>";
}
?>
</select>