我目前正在开发codeigniter。我想将每个员工的详细信息从mysql数据库登录到视图页面。员工登录的位置,并指向员工的页面。
我希望有人能帮我解决问题。基本上我已经创建了一个登录系统,而员工可以登录查看他们的详细信息(员工ID,姓名,名称,时间,超时,持续时间)。但我对如何根据已登录的人显示员工结果感到困惑。
例如,如果我登录用户名" JasonGriffin",结果将如下JasonGriffin's details
有2个mysql数据库表,一个名为员工,一个名为次&这是他们与此图像的关系employees and times relation
这是控制器(home.php)
public function goClock($message = null) {
$this->load->view('imports/header');
$this->load->view('imports/menu');
if (!is_null($this->input->post('login'))) {
$username = $this->input->post('user');
$password = $this->input->post('password');
$userdata = $this->model_home->get_userinfo($username, $password);
//$userdata += array('is_loggedin' => true);
//array_merge(array('is_loggedin' => true));
$_SESSION['is_loggedin'] = true;
if ($userdata !== false) {
$this->session->set_userdata($userdata);
if($userdata['user_type'] == 1){
redirect('home/goHome');
} else if ($userdata['user_type'] == 0){
redirect('home/goEmployee');
}
}else {
$data['login_error'] = '<p style="font-size: 16px; color: red;" align="center">Invalid Username or Password</p>';
$this->load->view('login', $data);
}
}else {
$data['username'] = $this->input->post('user');
$data['password'] = $this->input->post('password');
$this->load->view('clock', $data);
}
}
public function goEmployee() {
$this->load->model('Model_attendance');
$query = $this->Model_attendance->getEmployees();
$data['EMPLOYEES'] = null;
if ($query) {
$data['EMPLOYEES'] = $query;
}
$this->load->view('imports/header');
$this->load->view('imports/menu');
$this->load->view('employee', $data);
}
这是模型(model_attendance.php)
public function getEmployees() {
$this->db->select("*");
$this->db->from('employees');
$this->db->join('times', 'times.userID = employees.empnum');
$this->db->join('designation', 'designation.designation_id = employees.designation_id');
$query = $this->db->get();
return $query->result();
}
这是模型(model_home.php)
public function get_userinfo($username = null, $password = null) {
if ($username && $password) {
$this->db->select('username, password, empnum, user_type, lastname');
$this->db->where('username', $username);
$this->db->where('password', $password);
$query = $this->db->get('employees');
if ($query->num_rows()) {
return $query->result_array()[0];
}
}
return false;
}
这是视图(employee.php)
<table class="table table-striped responsive-utilities jambo_table" id="myTable">
<thead>
<tr class="headings">
<th>Employee ID</th>
<th>Name</th>
<th>Designation</th>
<th>Time-in</th>
<th>Time-out</i></th>
<th>Duration</th>
</tr>
</thead>
<tbody>
<?php foreach($EMPLOYEES as $employee){
$timein = $employee->timein;
$timein = explode(' ', $timein);
$date = nice_date($timein[0], 'F d Y');
$hour = $timein[1];
$regular_time_str = date( 'g:i A', strtotime( $hour ) );
$timein = $date . "  " . $regular_time_str;
if(!is_null($employee->timeout)){
$timeout = $employee->timeout;
$timeout = explode(' ', $timeout);
$date = nice_date($timeout[0], 'F d Y');
$hour = $timeout[1];
$regular_time_str = date( 'g:i A', strtotime( $hour ) );
$timeout = $date . "  " . $regular_time_str;
}else {
$timeout = ' ';
}
?>
<tr>
<td data-order="<?php echo $employee->timein; ?>"><?php echo $employee->userID; ?></td>
<td><?php echo $employee->name; ?> <?php echo $employee->lastname; ?></td>
<td><?php echo $employee->position; ?></td>
<td data-order="<?php echo strtotime($employee->timein);?>"><?php echo $timein; ?></td>
<td data-order="<?php echo strtotime($employee->timeout);?>"><?php echo $timeout; ?></td>
<td><?php
if($employee->hasClockOut==1){
$date1=new DateTime($employee->timein);
$date2=new DateTime($employee->timeout);
$employee->hours= $date1->diff($date2);
echo $employee->hours->format('%h')."H ".$employee->hours->format('%i')."M";
} else { echo " "; }
?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
答案 0 :(得分:-1)
{{1}}