phpcodeigniterselectresultset

Can I use ->row('column_name') in CodeIgniter to get the column value in the first row of the query result?


How can I access the value of an aliases column in the first row of the query result with CodeIgniter?

The following doesn't return the expected column value; it always returns null:

$qry_inp = 'SELECT table.value AS table_value FROM table';
$query = $this->db->query($qry_inp); 
echo $query->row('table_value ');

It doesn't matter if I use query builder methods or query().


Solution

  • Where is that behaviour documented? row doesn't take a column name as a parameter; it optionally takes a row number, and that's it. Access it like any other field:

    echo $query->row()->table_value;