gpt4 book ai didi

php - 如何从Codeigniter MYSQL中的大数据中获取员工的第一次和最后一次登录?

转载 作者:行者123 更新时间:2023-11-29 21:43:17 25 4
gpt4 key购买 nike

我有一个名为 Daily_data2 的表,其中包含用户生物识别机器的登录和注销详细信息。现在,用户可以登录并出去做一些工作,然后再次回来登录,并且可以多次执行此操作。因此,我只想获取特定用户的用户的第一次登录和该用户的最后一次注销。

现在我有一个名为 users 的表,其中包含所有用户名,并且我已从 daily_data2 表映射了 EMP_ID,以便对于每个用户,我可以知道哪个用户具有哪个 ID。

我有一个名为 view 的页面,在其中显示用户、他的 emp_id 以及登录或注销。在此之上,我保留了一个下拉列表,其中我从数据库传递了名称。

我想从下拉列表中选择一个名称并仅显示他的登录/注销详细信息。另外,我的代码获取所有登录/注销详细信息,我只希望它每天获取首次登录和最后一次注销。

这是我的代码:

View :

        <div class="row">
<div class="col-lg-12">
<div class="panel panel-primary">
<div class="panel-heading">
All Calls Records
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<div class="dataTable_wrapper">
<table class="table table-striped table-bordered table-hover" id="dataTables-example">


<thead>
<tr>
<th>Emp_ID</th>
<th>Name</th>
<th>Date</th>
<th>Entry</th>



</tr>
</thead>



<tbody>

<?php if(count($attendances)): foreach($attendances as $attendance): ?>


<tr class="odd gradeX">
<td><?php echo trim($attendance->emp_id,'">'); ?></td>
<td><?php echo trim($attendance->name,'">'); ?></td>
<td><?php echo trim($attendance->date_data,'">'); ?></td>
<td><?php trim($attendance->entry,'">'); ?> <?php if($attendance->entry >100)
{
echo "Logged In";
}
else
{
echo"Logged Out";
}?>
</td>


</tr>

<?php endforeach; ?>

<?php else: ?>

<tr>
<td colspan="3">We could not find any Data.</td>
</tr>

<?php endif; ?>



</tbody>
</table>
</div>
<!-- /.table-responsive

现在,一位 friend 推荐了此代码来获取第一次和最后一次登录/注销。但我没能理解它:

模型代码:

function get_attendance_history($emp_id) {

$hours = $this->time = date('Y-m-d H:i:s', strtotime('-1 month', time()));
//desc will print the newest records && asc the latest.
$sql = "SELECT * FROM daily_data2 WHERE emp_id = '{$emp_id}' AND date_data > '{$hours}' ORDER BY `date_data` desc /*LIMIT 1*/";

$result = $this->db->query($sql); //run the query
//print_r( $result->result_array() ); //debug the result
//return $result->row()->emp_id; //for one record show..
return $result->result_array();
}

Controller 代码:

  public function login_details() 
{

$this->data['attendances'] = $this->attendance_m->don();

$login_data =$this->data['attends']= $this->attendance_m->get_attendance_history('21');

$this->data['subview'] = 'admin/attendance/view';
$this->load->view('admin/_layout_main', $this->data);
var_dump($login_data);
}

我想展示这样的东西:

output

最佳答案

你可以试试这个从(中选择* SELECT * from (SELECT daily_data2.*,max(date_data) FROM daily_data2 WHERE emp_id = '{$emp_id}' AND date_data between '2015-01-01' AND '2015-01-31' group by emp_id order by date_data desc )作为一个 联盟 SELECT * from (SELECT daily_data2.*,min(date_data) FROM daily_data2 WHERE emp_id = '{$emp_id}' AND date_data between '2015-01-01' AND '2015-01-31' group by emp_id order by date_data desc )作为B

) 按 emp_id 排序

开始月份日期 = 2015-01-01end_month_date = 2015-01-31

关于php - 如何从Codeigniter MYSQL中的大数据中获取员工的第一次和最后一次登录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34311406/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com