Codeigniter:分组并从连接表中获取最新记录

$this -> db -> select('users.*');
$this -> db -> select('timerecord.*');
$this -> db -> from('users');
$this -> db -> join('timerecord', 'users.id = timerecord.id');
//$this -> db -> where(array('users.id'=>$user_id), NULL, FALSE);
$this -> db -> where('users.status', 'Verified');
//$this -> db -> where('users.id', 'timerecord.id');
$this -> db -> order_by('timerecord.timeId', 'DESC');
$this -> db -> group_by('timerecord.id, users.id');

i want to get records from both users and timerecord table but timerecord shows multiple rows because of duplicated id, and now i used group_by to limit the row in timerecord however the record is not showing the latest record i also used orderby but no luck, please someone help me, thanks!

can you try this?

$this -> db -> select('users.*');
$this -> db -> select('timerecord.*');
$this -> db -> from('users');
$this -> db -> join('timerecord', 'users.id = timerecord.timerecord.user_id');
//USE THE NAME OF THE ROW WHERE USER'S IDs ARE INSERTED ON YOUR TIMERECORD TABLE,
// THAT'S HOW YOU JOIN TABLE, RIGHT? 
// I ASSUME THAT YOU ARE JOINING USER'S ID AND TIMERECORD'S ID ON YOUR PREVIOUS POST //
//$this -> db -> where(array('users.id'=>$user_id), NULL, FALSE);
$this -> db -> where('users.status', 'Verified');
//$this -> db -> where('users.id', 'timerecord.id');
$this -> db -> order_by('timerecord.timeId', 'DESC');
$this -> db -> group_by('timerecord.id, users.id');
<div class="container">
    <script type="text/javascript">
        $(document).ready(function(){
            $('.approve').click(function(){
                return confirm("Verify this user?");
            });
            $('.delete').click(function(){
                return confirm("Are you sure you want to delete this account, everything will be deleted including its time record?");
            });
        }); 
    </script>
    <div class="empRec">
        <div class="empRec-content">
            <table class="tn">
              <tr>
                <th class="tn-4apw">Employee Name</th>
                <th class="tn-4apw">Date</th>
                <th class="tn-4apw">Day</th>
                <th class="tn-4apw">Time In/Out</th>
                <th class="tn-4apw"></th>
              </tr>
              <?php 
                foreach($getUsers as $row): 
                $timeStat = $row->status;
              ?>
              <tr>
                <td class="tn-ixdt"><?php if($timeStat == 'IN') { ?>
                    <img src="<?php echo base_url('assets/img/ico-online.png'); ?>" style="width:10px;">
                <?php } else { ?>
                    <img src="<?php echo base_url('assets/img/ico-offline.png'); ?>" style="width:10px;">           
                <?php } echo $row->name ?></td>
                <td class="tn-ixdt"><?php echo $row->dateToday ?></td>
                <td class="tn-ixdt"><?php echo $row->day ?></td>
                <td class="tn-ixdt"><?php echo $row->timeIn ?> - <?php echo $row->timeOut ?></td>
                <td class="tn-ixdt" style="text-align:right;"><button class="view" name="view"><img src="<?php echo base_url('assets/img/ico-view.png'); ?>"></img></button><button class="delete" name="delete"><img src="<?php echo base_url('assets/img/ico-delete.png'); ?>"></img></button></td>
              </tr>
              <?php endforeach; ?>
            </table>
        </div>
        <!-- Employee Record Content  -->
        <div class="empRec-bg"></div>
    </div>
    <!-- EMPLOYEE RECORD CONTAINER -->
</div>
<!-- CONTAINER -->
$this->db->query("SELECT users.*, timerecord.* FROM (users) 
JOIN timerecord ON users.id = timerecord.id WHERE users.status = 'Verified'
group by users.id, timerecord.dateToday order by dateToday")->get()->result();
$this->db->select('MAX(a.login_time) as login_time')

->from('bs_login_report a')

->group_by('a.user_id')

->get();

using this 'MAX(a.login_time) as login_time' you can achieve last row using