codeigniter, get the maximum value in mysql table column

感情迁移 提交于 2019-12-22 09:50:56

问题


i'm using codeigniter 2.
i've a mysql table column storing the time taken for each student.
eg. 1.2327, 0.6547, 1.9876

i want to get the max. value that column.

This is my code:

$this->db->select_max('time_taken', 'time');
$result = $this->db->get('students');  
echo $result->row()->time;

when i echo the result, it give me a value of 2(correct value should be 1.9876).
What is the correct way to get this value i need, thanks?


回答1:


Try:

$this->db->select_max('time_taken AS time');
$result = $this->db->get('students')->row();  
echo $result->time;

Edit: Make sure your database table field (i.e time_taken) is decimal, NOT integer.




回答2:


$this->db->select_max('time_taken');
$this->db->from('students');
$query=$this->db->get();
return $query->result_array();


来源:https://stackoverflow.com/questions/16538359/codeigniter-get-the-maximum-value-in-mysql-table-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!