CodeIgniter Forums
problem with mysql join - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: problem with mysql join (/thread-25528.html)



problem with mysql join - El Forum - 12-15-2009

[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?


problem with mysql join - El Forum - 12-15-2009

[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]


problem with mysql join - El Forum - 12-15-2009

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


problem with mysql join - El Forum - 12-15-2009

[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?


problem with mysql join - El Forum - 12-15-2009

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