02-25-2010, 07:59 AM
[eluser]andriu[/eluser]
Hi guys
I would like to start of to thank the users on this forum!!
And also say that I find CI amazing.
I'm pretty new to mysql and just discovered the power of "join"!!
Now i'm facing a problem
Ive got three tables
I try to join them like this:
In an incident I either save the elevator_id or the client_id depending on the type of incident.
(I know start to think that this was an error)
And now i want to be able to select the "elevator" or "client" depending on the incidencia
but if it is related to the elevator I also want to select the client.
With the code above I just get either the client or the elevator.
Is what im trying to do impossible with my table structure?
My old way of doing it is running another query for every incident!!
(a eleveator could change owner along the way and I would then want to select the new client)
Thanks in advance for any help!
Hi guys
I would like to start of to thank the users on this forum!!
And also say that I find CI amazing.
I'm pretty new to mysql and just discovered the power of "join"!!
Now i'm facing a problem
Ive got three tables
Code:
incidents
elevators
clients
a incident is connected either to a client or a elevator
a elevator is always connected to a client
I try to join them like this:
Code:
$this->db->from('incidencias');
$this->db->join('elevators', 'incidents_elevator_id = elevator_id', 'LEFT');
$this->db->join('clients', 'incidents_client_id = client_id', 'LEFT');
In an incident I either save the elevator_id or the client_id depending on the type of incident.
(I know start to think that this was an error)
And now i want to be able to select the "elevator" or "client" depending on the incidencia
but if it is related to the elevator I also want to select the client.
With the code above I just get either the client or the elevator.
Is what im trying to do impossible with my table structure?
My old way of doing it is running another query for every incident!!
(a eleveator could change owner along the way and I would then want to select the new client)
Thanks in advance for any help!