CodeIgniter Forums

Full Version: Two identicle column names on join
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Chris Williams[/eluser]
I'm using a left join on multiple tables where some id columns have the same name.

How to I rdisplay one over the other. I can't use a dot in php like I can in mysql.

Code:
<?=$row->user.user_id?>

This won't work.

El Forum

[eluser]ontguy[/eluser]
You could try adding an alias to the columns:
Code:
$this->db->select('user.id as User', 'address.id as Address');

El Forum

[eluser]Chris Williams[/eluser]
When I do this and look at the SQL output, it only grabs the first alias.

El Forum

[eluser]ontguy[/eluser]
I made a mistake in the code, it should be:
Code:
$this->db->select('user.id as User, address.id as Address');

El Forum

[eluser]marcoss[/eluser]
[quote author="Chris Williams" date="1213402766"]When I do this and look at the SQL output, it only grabs the first alias.[/quote]

You should provide a sample of your code, seems like you may have an error in there.

El Forum

[eluser]Chris Williams[/eluser]
Actually, ontguy nailed it.

I probably should have made sure my columns are all unique, but there you have it. :-)