Welcome Guest, Not a member yet? Register   Sign In
Same database column names when iterating through database results
#1

[eluser]cinoob[/eluser]
I have created a query using an inner join on two tables. I want to find the value of the ID column to pass into eg:

Code:
<?php echo anchor('event/eventdetails/'.$row->id, 'View details'); ?>

The problem is that my database query is returning more than one column name with called id from the tables and so the link is pointing to the wrong location. Is there any way I can say which table I want the column name to come from?
#2

[eluser]CI Coder[/eluser]
I take it the both tables have a column named "id". Either change the name of that column in one of the tables and the query accordingly, or use something like "SELECT table1.id as id, table2.id as id1, ... from table1 INNER JOIN table2 ON table1.id = table2.id". I'm not sure however that you need to select table2.id column at all.

Hope that helps.
#3

[eluser]cinoob[/eluser]
[quote author="CI Coder" date="1258947656"]I take it the both tables have a column named "id". Either change the name of that column in one of the tables and the query accordingly, or use something like "SELECT table1.id as id, table2.id as id1, ... from table1 INNER JOIN table2 ON table1.id = table2.id". I'm not sure however that you need to select table2.id column at all.

Hope that helps.[/quote]


Thanks, changing the select statement works perfectly using AS.




Theme © iAndrew 2016 - Forum software by © MyBB