CodeIgniter get value from Max

166 views Asked by At

How to get value from MAX('table')?

This is the code

Array
(
    [0] => stdClass Object
        (
            [applicant_id] => A001
            [MAX(education_type)] => 6
        )
)

To get the value from 'applicant_id' i simply using this

foreach ($results as $row) {
echo "<td>";
echo $row->applicant_id;
echo "</td>";
}

but it is failed when i try to echo $row->education_type; any idea?

2

There are 2 answers

2
Sadikhasan On BEST ANSWER

Have you try this one?

echo $row->{"MAX(education_type)"}
1
웃웃웃웃웃 On

Provide a aliasing for education_type column in the query while fetching the data. I guess your query is now like this

select applicant_id,MAX(education_type) from table;

if you need to use echo $row->education_type in your code then change your query to

select applicant_id,MAX(education_type) as education_type from table;