3

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?

2 Answers 2

8

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.

Sign up to request clarification or add additional context in comments.

4 Comments

i still get the same value 2
What data type is the database field?
haha, it was integer, i'll change it and see what's happen, thanks
try: $this->db->select('MAX(time_taken) AS time',false);
1
$this->db->select_max('time_taken');
$this->db->from('students');
$query=$this->db->get();
return $query->result_array();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.