CodeIgniter Forums
Compare two variables of differents tables with active record.. - 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: Compare two variables of differents tables with active record.. (/thread-55920.html)



Compare two variables of differents tables with active record.. - El Forum - 11-16-2012

[eluser]masentinel900[/eluser]
Hello everyone, In this moment I want to do a comparation of two differents tables for may use it like result.

So
Code:
$this -> db -> select('*');
$this -> db -> from('functions, users');
$this -> db -> where('idprofile=' . 'createdby');
$query = $this -> db -> get();
return $query;

I'm doing a table that to show two varables of the functions table but I have a row in the database which is "createdby" and its a number, But I want that show the name of the person, For this I have a foreign key, from the createdby row from functions to idprofile from users. So I want that Instead of to show the number of createdby. Show the name of the person about to the corresponding.

Someone that may help me please. Ideas!!!


Compare two variables of differents tables with active record.. - El Forum - 11-16-2012

[eluser]Mirge[/eluser]
http://ellislab.com/codeigniter/user-guide/database/active_record.html#select

Look at the "join()" method.


Compare two variables of differents tables with active record.. - El Forum - 11-16-2012

[eluser]masentinel900[/eluser]
Thanks by your response.

Will be like this:
Code:
$this -> db -> select('*');
$this -> db -> from('funciones, usuario');
$this -> db -> join('usuario', 'usuario.idusuario = funciones.creadopor');
$query = $this -> db -> get();
return $query;

But of this way donĀ“t works.


Compare two variables of differents tables with active record.. - El Forum - 11-16-2012

[eluser]Mirge[/eluser]
"This way don't works" doesn't help. What is the result you're getting? What result are you expecting? Details please, or NOBODY will be able to help very well.


Compare two variables of differents tables with active record.. - El Forum - 11-16-2012

[eluser]masentinel900[/eluser]
Again thanks by your responses.

see. I need to show a table with 3 rows of the table functions and one row more but of the table ID in the same function.

So I have this. ||name ||lastname ||father || mother|| -> Captions.
I going to show this: ||Diego ||Dominguez ||somenone || 1 || -> these info is from my table x.

Now I want to show this: ||Diego ||Dominguez ||someone || linda || -> The linda data is from my table users.

My table x is like this: ||id||Diego ||Dominguez ||somenone || 1 ||
My table users is like this: ||id||worker ||tall ||george || linda ||

I need that Instead of to show 1 show the name of the mother, The rows are links with a foreign key..

Obvisuly that is a example but this is basically I want to do..