Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Acessing fields with periods on the name
#1

[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.
#2

[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;
#3

[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.
#4

[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




Theme © iAndrew 2016 - Forum software by © MyBB