dongpu1315 2016-01-06 07:56
浏览 66
已采纳

如何从codeigniter中的数据库返回最后一条记录?

I am trying to get the last date for which I have the data. So I want to print the last date in my column date_data.

In Model:

public function last_record()
{ 
    $query = $this->db->select('LAST(date_data)');
    $this->db->from('date_data');
    return $query;
}

In Controller:

$last_data = $this->attendance_m->last_record();
var_dump($last_data);

But I am not getting the desired result

  • 写回答

6条回答 默认 最新

  • dougekui1518 2016-01-06 07:58
    关注

    Try this

    $query = $this->db->query("SELECT * FROM date_data ORDER BY id DESC LIMIT 1");
    $result = $query->result_array();
    return $result;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?