CodeIgniter Forums
[SOLVED] Acessing fields with periods on the name - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: [SOLVED] Acessing fields with periods on the name (/showthread.php?tid=37149)



[SOLVED] Acessing fields with periods on the name - El Forum - 12-29-2010

[eluser]Unknown[/eluser]
Hi all.

I'm doing a SQL query that's sort of this one:
Code:
SELECT A.ID, B.ID, B.NAME FROM A, B WHERE A.ID=B.ID

I run it with the command "$this->db->query($sql);" with the above SQL and then pass the results to a view.

But when I try to get the columns like:
Code:
$row = $query->row();
echo $row->A.ID;

It gives me the error "A PHP Error was encountered Severity: Notice Message: Trying to get property of non-object" on the "echo $row->A.ID;" line.

How can I get the value of these fields with a period on the name?

Thanks very much for any help.

Cheers.


[SOLVED] Acessing fields with periods on the name - El Forum - 12-29-2010

[eluser]cideveloper[/eluser]
Code:
SELECT A.ID as a_id, B.ID as b_id, B.NAME as b_name FROM A, B WHERE A.ID=B.ID  

$row = $query->row();
echo $row->a_id;



[SOLVED] Acessing fields with periods on the name - El Forum - 12-29-2010

[eluser]CroNiX[/eluser]
As programmer eludes to, when you are querying multiple tables and those tables (or even aliased tables) contain the same field name, you should use SELECT table.field AS yyy to cast it as a "unique" field name.


[SOLVED] Acessing fields with periods on the name - El Forum - 01-01-2011

[eluser]Unknown[/eluser]
Awesome, guys. Thanks! It solved my problem.

I tried a similar approach earlier but with quotation marks and it didn't worked. It's all fine now. Thanks again. Smile