CodeIgniter Forums
result() as $row key problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: result() as $row key problem (/thread-33608.html)



result() as $row key problem - El Forum - 09-01-2010

[eluser]Unknown[/eluser]
Hi.

I'm doing my first project in CI and I copied over a long mysql query from previous work. The result() it produces is an array with a SUM(table.COLUMN) key. Normally with PHP fetching
Code:
$row['SUM (table.COLUMN')]
works, but in CI using
Code:
$row->SUM (table.COLUMN)
it interprets it as "undefined method stdClass::SUM()".

I have spent all afternoon trying whatever I could think of to call the key differently. Can anyone help me out? I am still wondering if I should learn the active records method of producing queries but I am afraid that in the end I will be missing functionality and always be reverting to mysql queries anyway. Thanks anyone.


result() as $row key problem - El Forum - 09-01-2010

[eluser]danmontgomery[/eluser]
Alias the result column in your query

Code:
SELECT SUM(table.column) AS some_col ...

Code:
$row->some_col



result() as $row key problem - El Forum - 09-01-2010

[eluser]Unknown[/eluser]
Thank you very much. In honour I made it "AS noctrum".


result() as $row key problem - El Forum - 09-01-2010

[eluser]danmontgomery[/eluser]
ha!