Welcome Guest, Not a member yet? Register   Sign In
problem with mysql join
#1

[eluser]bhbutter123[/eluser]
I have two tables, for the most part the joins I am performing are working great but one column is the same in both tables - the id column which is the primary key. When I join the two tables the id from one is overwriting the id from the other one. Here is my model's code:

function get(){
$this->db->select('*');
$this->db->from('ci_businesses');
$this->db->join('ci_users', 'ci_users.id=ci_businesses.owner_id');
$query = $this->db->get();
$result = array();
foreach($query->result_array() as $row){
$result['listings'][] = $row;
}
return $result;
}
Is there something I am doing wrong or something I can add to have both id columns kept?
#2

[eluser]jedd[/eluser]
This pops up in the forums every few minutes.

There's two threads that are current right now, in fact. Have you been reading other threads?

Have a read through of these two:
[url="http://ellislab.com/forums/viewthread/138488/"]http://ellislab.com/forums/viewthread/138488/[/url]
[url="http://ellislab.com/forums/viewthread/138436/"]http://ellislab.com/forums/viewthread/138436/[/url]
#3

[eluser]bhbutter123[/eluser]
thanks for those links, I had looked before posting but I guess not enough, I found exactly what I need, thanks a bunch.
#4

[eluser]Jeroen Brussich[/eluser]
[quote author="jedd" date="1260923054"]This pops up in the forums every few minutes.

There's two threads that are current right now, in fact. Have you been reading other threads?

Have a read through of these two:
[url="http://ellislab.com/forums/viewthread/138488/"]http://ellislab.com/forums/viewthread/138488/[/url]
[url="http://ellislab.com/forums/viewthread/138436/"]http://ellislab.com/forums/viewthread/138436/[/url][/quote]


Wikki Wikki?
#5

[eluser]jedd[/eluser]
[quote author="Jeroen Brussich" date="1260924268"]
Wikki Wikki?
[/quote]

Done and done.

Check out the new bit in the [url="http://codeigniter.com/wiki/SQL/"]SQL FAQ[/url] for my spiel on this particular problem.




Theme © iAndrew 2016 - Forum software by © MyBB