Welcome Guest, Not a member yet? Register   Sign In
MySQL Join and active record issue (tables have same named fields)
#1

[eluser]skattabrain[/eluser]
I'm stumped here. I run this query ...

Code:
$this->db->from('users');
$this->db->where('id', $userID);
$this->db->join('clients', 'clients.clientID = users.clientID');
$this->db->limit(1);
$query = $this->db->get();

which ends up looking like this ...

SELECT * FROM (`users`) JOIN `clients` ON clients.clientID = users.clientID WHERE `id` = '3' LIMIT 1

Problem - both the users and the clients table have columns called 'aol' and 'msn' ... but if i do a var_dump on my query result, it looks like it's dropping 1 of the aol's. if i do the same query in a console ... i get both values.

So how do I access these variables? I used to do it by doing a select from 'table1', 'table2' ... will i have to explicitly build my select clause? ie ... select clients.aol, users.aol etc ...
#2

[eluser]charlieD[/eluser]
I had this issue yesterday - what I had to do was use the AS keyword:

$this->db->select('users.aol AS usersAOL, 'clients.aol AS clientsAOL');
$this->db->from('users');
etc...
#3

[eluser]skattabrain[/eluser]
thanks charlie ... i was hoping to still use select * but this will probably not be possible with active record.
#4

[eluser]Référencement Google[/eluser]
[quote author="skattabrain" date="1212534791"]thanks charlie ... i was hoping to still use select * but this will probably not be possible with active record.[/quote]

And so would it be also without Active Record...




Theme © iAndrew 2016 - Forum software by © MyBB