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

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: result() as $row key problem (/showthread.php?tid=33608)



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!